Docker Tips¶
Random useful docker stuff
Commands¶
Commonly used commands:
# build
docker build -t my-haproxy .
#test
docker run -it --rm --name haproxy-syntax-check my-haproxy haproxy -c -f /usr/local/etc/haproxy/haproxy.cfg
# run
docker run -p 53000:3000 -d --name haproxy --sysctl net.ipv4.ip_unprivileged_port_start=0 my-haproxy
# run - and map a file from host to container
docker run -d -v $HOME/.aws/credentials:/home/gitlab-runner/.aws/credentials:ro --name visionect-runner-visionect visionect-runner:latest
# Multiple arguments
docker run -it --entrypoint /bin/ls -v ~/.home:/myapp -p 9000:8080 -e FOO=BAR IMAGE_ID:latest -l -a -h --color=auto
# logs
docker logs haproxy
# get a shell
docker exec -it haproxy /bin/bash
# get a shell as root
docker exec -u 0 -it haproxy /bin/bash
# start from scratch
docker kill haproxy; docker rm haproxy; docker build -t my-haproxy . ; docker run -p 53000:3000 -d --name haproxy --sysctl net.ipv4.ip_unprivileged_port_start=0 my-haproxy
# Check entry point of existing image
docker inspect -f '{{.Config.Entrypoint}}' IMAGE_ID
docker inspect -f '{{.Config.Cmd}}' IMAGE_ID
# Overwrite the entrypoint for trouble shooting
docker run -it --entrypoint /bin/bash IMAGE_ID
docker ps -a # List containers
docker image ls # List images
# Remove container
docker rm CONTAINER_ID
# Clean unused containers
docker system prune
# Inspect what prune does yourself
docker container ls
docker image ls
docker volume ls
docker network ls
docker info
# Delete an image
docker rmi IMAGE_ID
Multiple arguments for entrypoint¶
If you need to pass multiple arguments to the entry point, you do that in a very convoluted way. The rule is to add all the arguments in the following order:
Normal docker run command
--entrypoint
(no arguments allowed here/bin/bash
allowed but/bin/bash -c
not allowed)Any other docker parameters
Image name
After the image, specify all the arguments to the entrypoint
Example:
docker run -it --entrypoint /bin/ls -v ~/.home:/myapp -p 9000:8080 IMAGE_ID:latest -l -a -h --color=auto
In the above example /bin/ls -l -a -h --color=auto
will be run.
Check digest of image¶
You can get the long digest like this and compare it on docker hub.
docker image inspect --format '{{.RepoDigests}}' visionect/visionect-server-v3
Install stuff¶
Check the distribution:
cat /etc/os-release
Ubuntu or Debian, use apt:
apt update
apt install package
# Ping command
apt install iputils-ping
CentOS / Red Hat, use yum:
yum install package
Alpine Linux, use apk:
apk update
apk add package
# This will install telnet via busybox-extras
apk add busybox-extras
Restart Docker Daemon from CLI / SSH on OSX¶
# Find docker process
launchctl list | grep docker
# Output:
98605 0 com.docker.docker.6300
# Stop docker get number from above
launchctl stop com.docker.docker.6300
# Start it again
open --background -a Docker
I have no idea why the launchctl start
command does not work for me where
stop
does work.
Random Errors¶
failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = failed to create LLB definition: circular dependency detected on stage: stage-0
At some point I pasted in the below which is causing the circular dependency error above:
COPY --from=0 / /
Comments
comments powered by Disqus