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

# 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

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