Jhonattan Rivera

00. Docker ๐Ÿ‹ - Cheat Sheet

Hey there! This quick document contains some useful commands and use cases when you're working with Docker. Feel free to write me for share your comments or feedback, through my LinkedIn.

Let's start!

container


๐Ÿ”น Run a container:

docker run <image_container> # standard
docker run --name <name_container> <image_container> # named container

๐Ÿ”น Run a container, mapping a host port to a container port.

docker run -p <host_port>:<container_port> <image_container>
# host_port : container_port

... example:

docker run -p 8080:80 nginx

๐Ÿ”น Restart a containers:

docker restart <container_id>

๐Ÿ”น List of containers:

docker ps # active containers
docker ps -a # all containers

๐Ÿ”น Run bash and have access to the container:

docker exec -ti <container_id> bash

๐Ÿ”น Run a container with a volume:

docker run -v <volume_name>:<mount_point>:<options> <image_container>

... example:

  • Volume -> test
  • Mount point on the container -> /apps
  • Options -> rw (Lectura y escritura)
docker run -v test:/apps:rw nginx

๐Ÿ”น View container logs:

docker logs <name_container>

๐Ÿ”น Update memory ๐Ÿ’ก:

docker update --memory "XXXm" <container_id>

Deleting things ๐Ÿ‹

Containers

๐Ÿ”น Delete a container:

  • It can be done both by name and by ID
docker kill <container_id> # first kill the container
docker container rm <container_id> # then, remove it

๐Ÿ”น Delete a container even if it's up. Forcing it:

docker rm -f <id_container>

๐Ÿ”น Stop a container:

docker stop <id_container>

๐Ÿ”น Start a stopped container:

docker start <id_container>

Volume

๐Ÿ”น List and delete volumes:

docker volume ls
docker volume rm <container_id>

Extra: AWS Practical Cases

Apply for EC2 instances:

๐Ÿ”นLogin into the instance:

ssh -i <your_pem_certificate> ubuntu@<public_ec2_ip>