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!
๐น 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>