Posts

Showing posts from 2017

Useful docker commands

Image
Stop All Docker Containers docker stop $(docker ps -q) Remove All Docker Containers docker rm $(docker ps -a -q) Remove All Docker Images docker rmi $(docker images -q)

Copy files to/from host to docker container

Image
Sometimes you need to save a log file form a container that you are running. For example you have an apache tomcat container and you want to save the access log to your local host. This what you do: #start the container docker run -d -p 8080:8080 --name tomcat9 tomcat:9-alpine #copy the access log to the hosts current directory docker cp tomcat9:/usr/local/tomcat/logs/localhost_access_log.2017-09-07.txt . Where /usr/local/tomcat/logs/localhost_access_log.2017-09-07.txt is the location of the file to copy and  . is your local folder. Adding a file to the container is similalry simple: docker cp myhostscript.sh tomcat9:/usr/local/tomcat/bin/. This will add the file myhostscript.sh to the running container's /usr/local/tomcat/bin folder. Reference: Docker documentation on cp

nginx: [emerg] host not found in upstream

I encountered the above error message on container start up when I was using the nginx docker image. There are several answers to be found on the Internet in relation to this problem, but somehow none of them worked for my case. I run the nginx docker command from command line like this: docker run --name nginx -p 80:80 \ -v ${HOME}/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \ -it --rm nginx:1.13 In my nginx.conf file I had my upstream defined like this:  upstream authenticator {            server myserver;     } Where myserver was a separate internal host. The suggested solution is to add a resolver directive to the config with the ip of the nameserver. resolver 1.1.1.1;  upstream authenticator {            server myserver;     } That didn't work either. After investigating the containers /etc/resolve.conf file I found that it points to 8.8.8.8 that is the google dns. Because myserver is in fact an internal server it wouldn't resolve of course and se

tar: Exiting with failure status due to previous errors

If you are here it is likely that you are trying to make sense of the message above. In my experience it highlights that in the directory sturcture that you try to tar together there are some files that tar -> ie.: your user doesn't have read access to.

Running C++ in a browser

Image
If you are a c/cpp developer and want to run your code on a web, in browser there is a solution for you. First make sure that you code is portable ie.: can be compiled on multiple platforms. Then you can use a compiler called Emscripten that is capable to output asm.js compatible javascript code or webassembly code. Sounds good? There is more if your code uses OpenGL ES it will cross compile that to WebGL. Setting up the actual enviroment is a breeze as there is a docker container for that on docker hub.

Enable haproxy stats page

I used the following config values with tthe HAProxy 1.7 docker image to enable the statistics page. listen stats bind :2016 stats enable stats hide-version stats realm Haproxy stats uri /ha-stats stats auth admin:password  This will bind to port 2016 on your host and will reqest the username and password specified.

Detecting available java heap space in a contaner

Did you know that java before update 8u131 would ignore your container memory limit and simply would calculate heap size from the host memory size? Carlos Sanchez has written an excellent post about the subject. Please follow the link to his site to read it. Running a jvm in a container without getting killed.

Sharing private docker images

There are situations when we need to distribute our images without docker hub. As you know docker hub is public docker registry therefore anyone can see the images uploaded. You can choose to pay for a private account, but that would still involve transferring the image to the hub and back. Sometimes we just want to copy our confidential images form one host to another. A simple way to achieve this to use: docker save imagename > imagename.tar This will take the image form your local docker repository and exports it to a tar file. One can use gzip to compress the image further. Loading the images on a different host also straightforward. docker load -i imagename.tar Docker will restore the image with its layers into the new repository.

Untag a docker image

Problem: I have more than one tag on an image in my docker repository. Solution: Docker hasn't got untag command, but if you remove the image using its tag it will untag it for you. docker rmi imagetag

Running docker without sudo

Problem: I don't want to use sudo all the time when I issue docker commands. Solution: Create a docker group: sudo groupadd docker Add your user to group: sudo gpasswd -a myuser docker Restart docker service: sudo service docker restart Login to your newgroup: newgrp docker Source https://askubuntu.com

Making changes in a running docker container

In this example I assume that you are using a tomcat contanier and a webapp deloyed in the container. Problem:  I have a webapp running in a docker container and I want to change the log level. Solution: Get a bash shell into your container. docker exec -it containerid /bin/bash Do the change that you need to do. Stop your container docker stop containerid Start your container docker start containerid This change will not get saved into the image as soon as you destory your container instance you will loose the change.

Debug a running docker container

Problem: I have a running docker container how can I peek inside? Solution: docker exec -it containerid /bin/bash This will give you a bash shell in the container.

Debug a docker container failing to run

Problem: I was building a new docker image and it failed to run every time I tryied. As you know if the container isn't running you can't peek inside. Solution:: Run bash using the image so you can poke around to find the cause. docker run -it imagename /bin/bash