The Ultimate Docker Cheat Sheet: 20 Questions Answered

docker training in chennai

Docker is a powerful tool that has revolutionized the way we develop and deploy applications. In this blog post, we’ll answer 20 questions based on the Ultimate Docker Cheat Sheet to help you understand Docker better.

1. What are the guidelines for building secure Docker images?

There are several guidelines for building secure Docker images:

# 1. Prefer minimal base images
# 2. Dedicated user on the image as the least privileged user
# 3. Sign and verify images to mitigate MITM attacks
# 4. Find, fix and monitor for open source vulnerabilities
# 5. Don’t leak sensitive information to docker images
# 6. Use fixed tags for immutability
# 7. Use COPY instead of ADD
# 8. Use labels for metadata
# 9. Use multi-stage builds for small secure images
# 10. Use a linter

You can find more information in Snyk’s 10 Docker Image Security Best Practices blog post.

2. How do you clean Docker?

Cleaning Docker involves several steps, including removing a running container, removing a container and its volume, removing all exited containers, removing all stopped containers, and removing a Docker image.

# Removing a Running Container
docker container rm nginx

# Removing a Container and its Volume
docker container rm -v nginx

# Removing all Exited Containers
docker container rm $(docker container ls -a -f \ status=exited -q)

# Removing All Stopped Containers
docker container rm `docker container ls -a -q`

# Removing a Docker Image
docker image rm nginx

3. How do you log in to a Docker Registry?

To log in to a Docker Registry, use the following commands:

docker login
docker login localhost:8080

4. How do you log out from a Docker Registry?

To log out from a Docker Registry, use the following commands:

docker logout
docker logout localhost:8080

5. How do you search for an image in Docker?

To search for an image in Docker, use the following command:

docker search nginx

6. How do you pull an image in Docker?

To pull an image in Docker, use the following commands:

docker image pull nginx
docker image pull eon01/nginx \ localhost:5000/myadmin/nginx

7. How do you push an image in Docker?

To push an image in Docker, use the following commands:

docker image push eon01/nginx
docker image push eon01/nginx \ localhost:5000/myadmin/nginx

8. How do you create and run a simple Docker container?

To create and run a simple Docker container, use the following command:

docker container run --name infinite -it -p 3000:80 -v \ ${PWD}:/data ubuntu:latest

9. How do you rename a Docker container?

To rename a Docker container, use the following command:

docker container rename infinite infinity

10. How do you remove a Docker container?

To remove a Docker container, use the following command:

docker container rm infinite

11. How do you update a Docker container?

To update a Docker container, use the following command:

docker container update --cpu-shares 512 -m 300M infinite

12. How do you install Docker Swarm?

To install Docker Swarm, use the following command:

curl -ssl https://get.docker.com | bash

13. How do you initialize Docker Swarm?

To initialize Docker Swarm, use the following command:

docker swarm init --advertise-addr 192.168.10.1

14. How do you get a worker to join the Swarm?

To get a worker to join the Swarm, use the following command:

docker swarm join-token worker

15. How do you get a manager to join the Swarm?

To get a manager to join the Swarm, use the following command:

docker swarm join-token manager

16. How do you list services in Docker Swarm?

To list services in Docker Swarm, use the following command:

docker service ls

17. How do you create a service in Docker Swarm?

To create a service in Docker Swarm, use the following command:

docker service create --name vote -p 8080:80 instavote/vote

18. How do you scale a service in Docker Swarm?

To scale a service in Docker Swarm, use the following command:

docker service scale vote=3

19. How do you update a service in Docker Swarm?

To update a service in Docker Swarm, use the following command:

docker service update --image instavote/vote:movies vote

20. How do you map the container port to a host port?

You can map the container port to a host port using the -p option in the docker run command. Here’s an example:

# Map the container port to a host port
docker run -p $HOST_PORT:$CONTAINER_PORT --name <container_name> -t <image>
docker run -p $HOST_PORT:$CONTAINER_PORT --name infinite -t infinite

In these commands, $HOST_PORT is the port on your host machine, and $CONTAINER_PORT is the port in the Docker container. The --name option is used to assign a name to the container.

We hope this blog post has helped you understand Docker better. Remember, the Ultimate Docker Cheat Sheet is a great resource to keep handy as you navigate your Docker journey.

If you’re looking to deepen your Docker knowledge and skills, consider enrolling in a Docker training course. For those based in Chennai, there are numerous Docker training programs available that offer comprehensive learning experiences, hands-on projects, and guidance from industry experts.

Docker training in Chennai can help you master the key concepts and techniques used in Docker, and equip you with the skills needed to excel in your career. Don’t wait, start your Docker training in Chennai today and take a step forward in your tech journey. Happy Dockering!

Jeevi Academy
Jeevi Academy
Leave Comment
Share This Blog
Recent Posts
Get The Latest Updates

Subscribe To Our Newsletter

No spam, notifications only about our New Course updates.