There is no specific order to these learnings. They're just the random learnings of a madman, trying to learn and use docker for the first time... So, I'm just throwing them out there as I recall them. I said "madman," right? Of course these aren't in any order...
- the issues I faced -
First, the backstory
I'm running Windows Home on the insider program. So, naturally, I decided to go with WSL 2, running Ubuntu-18.04, and the Docker edge build for the insider release. Unfortunately, this was riddled with issues, and it only worked for a couple of days, before I started having problems getting it to connect to the docker daemon in Windows. I troubleshot this for a couple of days, and each time I was close toa fix, something in Docker or WSL would blow up, and I'd have to start all over again. I finally decided to uninstall docker, kill WSL, and go back to the old ways... Run an Ubuntu VM and run docker from within there.
Some of the key issues that I ran into are:
- Installation - by default, no one wants you to do it this way anymore.
- Sharing folders between the host and the VM.
- Connecting to the docker daemon friggin again
- Permissions issues.
Install docker
# install docker
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce
sudo systemctl status docker
# Run docker without sudo
sudo usermod -aG docker ${USER}
Install docker-compose
# install docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# set permissions
sudo chmod +x /usr/local/bin/docker-compose
# validate success by checking version
docker-compose --version
verify docker works
docker run hello-world
permissions
sudo groupadd docker
sudo usermod -aG docker $USER
sudo chmod 755 -R
newgrp docker
Restart your computer
validate that dockerd is running
who owns the docker sock?
ls -l /var/run/docker.sock
take ownership -
sudo chown *your-username* /var/run/docker.sock
Note: Ubuntu doesn't support docker-compose file of version 3.7 yet, so I had to revert back to ver 3.3
if you keep trying to update your password, and it's just not working
Validate your vars...
and remember that an environment variable defined in the docker-compose file takes precedence
grafana:
image: grafana/grafana
container_name: grafana # simplify your container names...
ports: # used to connect host:comtainer ports
- 3000:3000
expose: # used to expose a port outside the network
- 3000
volumes:
- grafana_data:/var/lib/grafana
- ./grafana/provisioning:/etc/grafana/provisioning/
environment: # declared vars take precedence over env_file
- GF_SECURITY_ADMIN_PASSWORD=${GF_SECURITY_ADMIN_PASSWORD}
- GF_AUTH_ANONYMOUS_ENABLED=${GF_AUTH_ANONYMOUS_ENABLED}
- GF_USERS_ALLOW_SIGN_UP=${GF_USERS_ALLOW_SIGN_UP}
- GF_INSTALL_PLUGINS=${GF_INSTALL_PLUGINS}
env_file:
- ./.env
networks:
- private
- public
restart: always
Did you accidentally use " or ' on your vars, and you weren't supposed to?
GF_SECURITY_ADMIN_PASSWORD="abc123"
passes "abc123"
GF_SECURITY_ADMIN_PASSWORD=abc123
passes abc123
If your vars are good, then wipe your browser cache and kill your persistent storage volume, if you created one...
version: '3.3'
# changed from 3.7 to accommodate running from ubuntu
volumes:
prometheus_data: {}
grafana_data: {}
docker-compose down
docker volume prune
docker-compose up -d
99% of the time, that did the trick for me...
I've noticed that a lot of Dockerfiles are poorly constructed (and I'm a novice). I suggest running with build, to test how solid the images are that you plan to incorporate...
One such painful image was...
FROM node:13-alpine
WORKDIR /app
COPY package.json yarn.lock /app/
RUN \
apk add --no-cache tini && \
yarn --silent --no-progress --frozen-lockfile
COPY . /app/
EXPOSE 3000
ENTRYPOINT ["yarn"]
CMD ["start"]
# ENTRYPOINT ["tini"]
# CMD ["yarn", "start"]
I couldn't get it to build until I changed COPY package.json yarn.lock /app/
to COPY . /app/
and even then, it was a crap image that continuously restarted, because I could never get it to properly take the supplied package.json
...
Don't waste your time with images that can't build from their published Dockerfile... My 2 cents
TL;DR
more to come
For some reason, prometheus doesn't work well with exporters inside a docker built network. I tried to make it work for 2 days, to no avail, and all of the prometheus group resolutions include having the user change to host
network, versus bridge
, or overlay
So, update your damn sources to use:
network_mode: host
example:
blackbox:
image: prom/blackbox-exporter
container_name: blackbox
volumes:
- ./blackbox/config:/config
command:
- '--config.file=/config/blackbox.yml'
network_mode: host
docker exec -it <container name> <command>
as an example:
docker exec -it prometheus sh
You can also remotely run commands in this manner.
- docker-compose cheat sheet
- docker cheat sheet
- https://stackoverflow.com/questions/33562109/docker-command-cant-connect-to-docker-daemon