docker
Docker uses containers, and is probably at the exact level I want to use.
note above this line was moved to /ops/virtualization/docker.md
debugging
The easiest way to look around in an image that is already started is :
| execute commands inside the container | |
|---|---|
Note that sh is a command that works for both debian/bash and alpine/ash. For a non-running container, like builder containers etc, you use run :
| execute commands inside the container | |
|---|---|
registry
To be able to deploy from the internet you can use the docker hub : visit
There you can maintain repositories, and when you click on them it show what the format is that you should push and pull from.
for example, for the klopt repository :
| push an image to the repository | |
|---|---|
However you should first associate a docker image with that tagname. I had made a Dockerfile for the doc project and named it 'docker-doc'
If you list it, you will see it is now the repository name :
Now first give the docker-doc an tagname on the repository, and then push it.
Now the repository is also available as kees/klopt:doc at the hub.
| list images | |
|---|---|
So on another (deployment) machine, you can now :
| login to repo | |
|---|---|
The publish redirects all html traffic to port 8888 because 80 was already taken on the servert in question. Browser to visit and the complete web app runs !!
docker login
A word on docker login, note that it creates a file called ~/.docker/config.json
If you replace somebase64digits== with the value of the auth: line you will see that it is the plaintext username:password.
So this could be done more secure, with credential helpers. The ones suggested only leave :
- pass
- D-Bus Secret Service: visit
I know pass, so i m starting with that. The helper for pass is here : visit And it should be in the clients PATH for docker to find.
Now point docker to this helper in ~/.docker/config.json. Just remove the content or 'docker logout' and put this :
The format used is in the format docker-credential-<credsStore>. So this would suffice for docker-credential-pass. Now if you log in the content will also change but now it becomes :
| ~/.docker/config.json | |
|---|---|
No more clear credentials, they are now in pass :
| pass tree | |
|---|---|
The docker-credential-helpers has been added to the entries I already added. View them with :
| edit passwords | |
|---|---|
jenkins
Note that this invalidates the jenkins setup needed to push/pull from docker-hub. For now i prefer running devspace manually, but here is a guide on how it could be setup with another helper docker-credential-env : visit
Not. tried yet.
chaining builds
You can create images for building an application and then copy that over into another container like this :
This was the first draft of the backend Dockerfile before we split it into parts. Look at the highlighted lines the first one names the first images as builder, the second one specifies that it starts a new clean image again based on alpine which has not got all the software needed to build the builder image. The third line then specifies that it copies the executable from the builder into the clean image.
Needless to say the final image is much smaller. When you tag it this last imaged will receive the tag, the other one will be a nameless image.
| build from tag | |
|---|---|
splitting stages
Later on I split these two stages because the 3pty code almost never changed but still took very long to compile. This not only meant splitting the Dockerfile, but also the Jenkinsfile and the repository !! This is because Jenkins rebuilds are triggered by git commits and that would also mean that the 3pty code gets rebuilt at every change. Now the first part gets a separate tag :
| build from tag | |
|---|---|
And the second one becomes :
| Dockerfile | |
|---|---|
ansible
Ansible has commands for using docker. But to install it there are some problems if you don't have the correct version of pip :
| ansible | |
|---|---|
You might actually want to restore pip again after this because it is already at version 18! Anyway this works for installing ansible-container
Note that the next command will overwrite ansible.cfg if it is present !!
| initialize | |
|---|---|
Also the correct docker version should be installed .. sigh !!
Further reading:
troubleshooting
Got permission denied while trying to connect to the Docker daemon socket
| add to docker group | |
|---|---|
Cannot create an item in a locked collection
| install gnupg2 | |
|---|---|
failed to build: failed to start shim:
When running docker-compose. No explanation.. but last time this helped.
Failed COPY command
When using COPY and it fails with a message like 'not a directory'. For instance
| file existing | |
|---|---|
In this case, there was a file called 'backend' in the container.
cleanup all containers and images
If you want to start all over :
| cleanup and make some space | |
|---|---|
docker-proxy hogging ports
You have stopped a container, even a complete systemprune (see prev chapter) Still you can not get the ports you want.
If you use ps you can see that docker-proxy is still running :
To fix this, this works