docker run -d -p 80:80 --name webserver nginx
-v host-dir:container-dir
-p host-port:container-port
docker ps
Attach to existing container's shell
docker exec -it container_id /bin/sh
docker kill/stop $(docker ps -q)
docker build --no-cache .
docker-compose build --no-cache mysql
Delete all containers
docker rm $(docker ps -a -q)
Delete all images
docker rmi -f $(docker images -q)
Clean up disk space used by Docker
docker system df
docker system prune
Increase docker memory
In advance tab of preference, change the memory or cpu.
configure --memory 6g in docker run command to set a different value.
Disable container auto-run
docker update --restart=no my-container
List Docker Container Names and IPs
docker ps -q | xargs -n 1 docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{ .Name }}' | sed 's/ \// /'
docker stats
check memory and cpu usage
docker-compose up
Dockerfile
RUN creates an intermediate container, runs the script and freeze the new state of that container in a new intermediate image.
WORKDIR /path
ENTRYPOINT vs CMD
Prefer exec form over shell form
docker run --entrypoint [my_entrypoint] containter_name [command 1] [arg1] [arg2]
Use COPY if don't need ADD's specical features
Use dockerfile to build each image, docker compose file to assemble them.
EXPOSE 8983-8986
USER builder
docker-compose
up, down, logs,
scale service=number
docker-compose build
Volumes
1. absolute path or relative path started with ./ means local path
2. named volume that references from the volumes list
docker volume prune
docker volume ls
docker inspect $volume_name
Misc
Change hostname
docker run -it -h myhost ...
docker run --rm -it --cap-add SYS_ADMIN ...
Troubleshooting
docker logs $container_id
docker events &
-v host-dir:container-dir
-p host-port:container-port
docker ps
Attach to existing container's shell
docker exec -it container_id /bin/sh
docker kill/stop $(docker ps -q)
docker build --no-cache .
docker-compose build --no-cache mysql
Delete all containers
docker rm $(docker ps -a -q)
Delete all images
docker rmi -f $(docker images -q)
Clean up disk space used by Docker
docker system df
docker system prune
Increase docker memory
In advance tab of preference, change the memory or cpu.
configure --memory 6g in docker run command to set a different value.
Disable container auto-run
docker update --restart=no my-container
List Docker Container Names and IPs
docker ps -q | xargs -n 1 docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{ .Name }}' | sed 's/ \// /'
docker stats
check memory and cpu usage
docker-compose up
Dockerfile
RUN creates an intermediate container, runs the script and freeze the new state of that container in a new intermediate image.
WORKDIR /path
Prefer exec form over shell form
docker run --entrypoint [my_entrypoint] containter_name [command 1] [arg1] [arg2]
Use COPY if don't need ADD's specical features
Use dockerfile to build each image, docker compose file to assemble them.
EXPOSE 8983-8986
USER builder
docker-compose
up, down, logs,
scale service=number
docker-compose build
Volumes
1. absolute path or relative path started with ./ means local path
2. named volume that references from the volumes list
docker volume prune
docker volume ls
docker inspect $volume_name
Misc
Change hostname
docker run -it -h myhost ...
docker run --rm -it --cap-add SYS_ADMIN ...
Troubleshooting
docker logs $container_id
docker events &