Updated: 14 June 2023
Copy file from container to host
docker cp <:containerId>:/file/path/within/container /host/path/target
Copy file from host to container
docker cp /host/path/target <:containerId>:/file/path/within/container
Jersey & Guernsey, United Kingdom
Updated: 14 June 2023
Copy file from container to host
docker cp <:containerId>:/file/path/within/container /host/path/target
Copy file from host to container
docker cp /host/path/target <:containerId>:/file/path/within/container
Updated: 08 May 2023
Run an init
inside a container which forwards signals and reaps processes. Configure in a Dockerfile
FROM mcr.microsoft.com/dotnet/sdk
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
tini \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["/usr/bin/tini", "--"]
or docker-compose.yml
services:
web:
image: alpine:latest
init: true
https://github.com/krallin/tini
Tini is the simplest init you could think of. All Tini does is spawn a single child (Tini is meant to be run in a container), and wait for it to exit all the while reaping zombies and performing signal forwarding.
Updated: 23 June 2023
Compose file version 3 reference
Start just one service
docker compose up -d start_me
List containers in json format
docker compose ps --format json | jq .
Updated: 18 August 2023
A smarter Dockerfile linter that helps you build best practice Docker images. The linter parses the Dockerfile into an AST and performs rules on top of the AST. It stands on the shoulders of ShellCheck to lint the Bash code inside
RUN
instructions.
Use online at https://hadolint.github.io/hadolint
Run in a Docker container
docker run --rm -i hadolint/hadolint < Dockerfile
Updated: 08 April 2023
Run mysql inside docker
docker run -p 3306:3306 --name our-mysql -e MYSQL_ROOT_PASSWORD=hopeless mysql:latest
Updated: 12 February 2023
On Linux, IP address of the Docker host
172.17.0.1
Updated: 16 November 2023
View and follow container logs
sudo docker logs -f my-symf
View container logs via docker compose
docker compose logs certbot
docker compose logs --follow --timestamps --tail="all" <service>
Updated: 24 December 2022
List all docker volumes
docker volume ls
Inspect a volume
docker volume inspect my-vol
Delete a volume
docker volume rm my-vol
delete all volumes
docker volume rm $(docker volume ls -q)
Updated: 14 June 2023
Build and tag an image from a Dockerfile in the same directory
docker build -t node-demo .
Start a container
docker run -i -t ubuntu /bin/bash
docker run -it node:19 /bin/bash
docker run -it --rm -d -p 8080:80 --name web nginx
Docker compose
docker-compose up --build
docker-compose up --remove-orphans -d
Stop all containers
docker stop $(docker ps -aq)
Remove all containers
docker rm $(docker ps -aq)
List images
docker images
See which containers are running
docker ps
See all containers, including non-running
docker ps -a
Remove stopped containers and images, including unused and dangling images
docker system prune -a
Delete all images
sudo docker rmi $(sudo docker images -q) --force
Run a php script inside a container
docker run --rm -v $(pwd):/app -w /app php:cli php hello.php
Get ip address of container
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container name>
sudo docker inspect <container name> | grep IPAddress
Command prompt into a container
sudo docker exec -it bash
sudo docker exec -it wp-local-docker_phpfpm_1 /bin/sh -c "[ -e /bin/bash ] && /bin/bash || /bin/sh"
docker-compose exec --user www-data phpfpm bash
Keep a container running. From docker-compose.yml
services:
myservice:
command: bash -c "while true; do echo 'sleeping...' && sleep 10; done"
Updated: 16 November 2023
phpMyAdmin is available as a Docker image. The MySQL server connection parameters are provided when the container is instantiated.
For a remote MySQL server
docker run --name myadmin \
-e PMA_HOST=https://example.com \
-e PMA_PORT=3306 \
-e PMA_USER=user \
-e PMA_PASSWORD=password \
-p 8080:80 \
phpmyadmin/phpmyadmin
Browse to phpMyAdmin at http://localhost:8080
MySQL server running in a local Docker network some-network
docker run --name myadmin \
--network=some-network \
-e PMA_HOST=db \
-e PMA_PORT=3306 \
-p 8080:80 \
phpmyadmin/phpmyadmin
--network
The docker network the phpMyAdmin container will join.