-
Notifications
You must be signed in to change notification settings - Fork 0
Docker
alex [dot] kramer [at] g_m_a_i_l [dot] com edited this page Aug 19, 2021
·
15 revisions
Build image from Dockerfile, skip cache, with name and tag:
docker build --no-cache -t [NAME]:[TAG] [PATH TO DOCKERFILE]
Pull image from Docker Hub:
docker pull [REMOTE IMAGE NAME]
List all local images:
docker images
Inspect:
docker inspect [IMAGE NAME|ID]
History:
docker history [IMAGE NAME|ID]
Delete:
docker rmi [IMAGE NAME|ID]
Create container from image and start it backgrounded with mapped port (necessary for OSX) and mounted directory:
docker run -d -p [HOST PORT]:[CONTAINER PORT] --mount type=bind,source=[HOST DIR PATH],target=[CONTAINER DIR PATH] [IMAGE NAME|ID]
List containers:
docker ps # running containers
docker ps -a # all containers including stopped
docker ps --format "{{.Names}}" # running containers by name
docker ps -q # running containers by id
Bash shell for a running container:
docker exec -it [CONTAINER NAME|ID] bash
Start/stop/tail container:
docker start [CONTAINER NAME|ID]
docker stop [CONTAINER NAME|ID]
docker logs -f --tail 100 [CONTAINER NAME|ID] # stream logs of container starting 100 from the end
Delete:
docker rm [CONTAINER NAME|ID]
Run an image in the background:
docker run -[i|t] -d centos # run without foreground shell
docker run -it -d centos # run with foreground shell
docker run --entrypoint "/bin/sh" -it alpine/git # Alpine requires this for some reason...