-
Notifications
You must be signed in to change notification settings - Fork 0
Docker cheat sheet
Gabriel Araujo edited this page Jul 26, 2022
·
5 revisions
-
Docker containers will exit if no process is running inside it
-
If you are running something that needs input you have make the container
--interactiveand attach the--ttye.g:
docker run -it ruby:3.1.2-alpine vi -
Containers are meant to be disposable and won't persist any changes made inside it (Reference: https://docs.docker.com/storage)
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
e.g: docker run -it --rm ruby:3.1.2-alpine sh
You can use docker run --help to get the full OPTIONS list, but here are some important ones:
-i, --interactive Keep STDIN open even if not attached
-t, --tty Allocate a pseudo-TTY
--rm Automatically remove the container when it exits
--mount Attach a filesystem mount to the container
-d, --detach Run container in background and print container ID
-p, --publish list Publish a container's port(s) to the host
--name string Assign a name to the container
-w, --workdir string Working directory inside the container
Reference: https://docs.docker.com/storage/volumes/#choose-the--v-or---mount-flag
- with
--mountsyntax:docker run -it --rm --mount type=bind,src=$(PWD),dst=/usr/src/app ruby:3.1.2-alpine sh - with
-vsyntax:docker run -it --rm -v $PWD:/usr/src/app ruby:3.1.2-alpine sh
docker image ls List images
docker ps Shows only running containers
docker ps -a Shows all containers