-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
- good to just alias
docker="sudo docker"so that you don't have to typesudoevery time
See
docker ps: see running containersdocker container ls -a: see all containers, even those that have stoppeddocker images: see images on disk
Run
docker run <image_name>: run an image as a container- options
-p: expose a port inside the container to the host- e.g.
-p 8123:8123
- e.g.
-v: mount a volume on the host to the container- e.g.
-v /tmp:/usr
- e.g.
-d: run in detached mode-ti: add terminal driver and run in interactive mode-e: add environment variable- e.g.
-e MYSQL_USER=etture
- e.g.
- '--name`: designate a name for the container
- e.g.
--name my_container
- e.g.
- complete example:
sudo docker run -d -ti \ -p 8123:8123 -v /tmp/usr \ -e MYSQL_USER=etture \ --name my_container \ ubuntu:18.04 /bin/bash
- options
docker exec: run a command in a running container- e.g.
sudo docker exec -ti <container_name> /bin/bash- log in to the running container through an interactive shell
- e.g.
Remove
docker kill <container_name>: kill a container processdocker container rm <container_name>: remove a container from storagedocker rmi <image_name>: remove an image
Build
docker build -t <image_tag_name> .: build a new image using the Dockerfile in the current directorydocker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]: change name of an existing imagedocker push <image_tag_name>: push the image onto the Docker registry