Unable to implement WatchTower in Docker - docker

I am trying to implement Watchtower which auto-build a container if any updates are found in Docker image.
These are commands I used for implementing watchtower:
git clone https://github.com/linuxacademy/content-express-demo-app.git watchtower
cd watchtower/
git checkout dockerfile
docker login -u "MYDOCKERREPO"
docker image build -t MYDOCKERREPO/my-express .
docker image push MYDOCKERREPO/my-express
docker container run -d --name watched-app -p 80:3000 --restart always MYDOCKERREPO/my-express
docker container run -d --name watchtower
--restart always
-v /var/run/docker.sock:/var/run/docker.sock
v2tec/watchtower -i 15
vi .dockerignore
Dockerfile
.git
.gitignore
#Added comment in app.js
created a sample.js file
docker image build -t MYDOCKERREPO/my-express --no-cache .
docker image push MYDOCKERREPO/my-express
I waited for many hours but no changes came. Also while pushing updated docker image it didn't show a single Pushed. All were saying 'Layers already exists"
Please if someone can help
EDIT:
Dockerfile:
FROM node
RUN mkdir -p /var/node
ADD . /var/node/
WORKDIR /var/node
RUN npm install
CMD ./bin/www

I waited for many hours but no changes came. Also while pushing updated docker image it didn't show a single Pushed. All were saying 'Layers already exists"
This means that none of the layers (changesets) you pushed differed from the ones already pushed, and as such, no new hashes were produced. Watchtower will only detect and update when the image has actual changes.
docker container run -d --name watchtower --restart always \
-v /var/run/docker.sock:/var/run/docker.sock v2tec/watchtower -i 15
The image you're using is more than a year old at this point. It might (likely won't) be compatible with current docker versions. The latest release of the watchtower image is available at containrrr/watchtower:latest.

Related

How can I use Docker and Verdaccio, publish a package, then share that Docker Image to another person with the Package showing up?

I have got the Verdaccio running with docker on my system using:
docker pull verdaccio/verdaccio
docker run -it --rm --name verdaccio -p 4873:4873 verdaccio/verdaccio
I can then see my Verdaccio at localhost:4873.
I add a user:
npm adduser --registry http://localhost:4873/
I go to a simple package repo and publish it:
npm publish --registry http://localhost:4873/
I then go to the browser and see my package is in the list on localhost
I then rename my docker container:
docker rename 4d2b---3692 my-container
On docker hub I have a repo called myuser/my-container
I then commit my container
docker commit 93ba9d----e myuser/my-container
Then I push it to Docker Hub (I did log in already)
docker push myuser/my-container
I see that it is updated on my Docker Hub.
I remove everything related to Docker on my computer
docker rmi --force 93ba9d----e
I then see nothing when I run these commands
docker ps -a
docker images
Then I try and pull my container
docker pull myuser/my-container
I then run my container
docker run -it --rm --name verdaccio -p 4873:4873 myuser/my-container
I can then see the Verdaccio page on localhost:4873, however I can not see the published package.
Please let me know what I am missing, thanks.

Docker basics, how to keep installed packages and edited files?

Do I understand Docker correctly?
docker run -it --rm --name verdaccio -p 4873:4873 -d verdaccio/verdaccio
gets verdaccio if it does not exist yet on my server and runs it on a specific port. -d detaches it so I can leave the terminal and keep it running right?
docker exec -it --user root verdaccio /bin/sh
lets me ssh into the running container. However whatever apk package that I add would be lost if I rm the container then run the image again, as well as any edited file. So what's the use of this? Can I keep the changes in the image?
As I need to edit the config.yaml that is present in /verdaccio/conf/config.yaml (in the container), my only option to keep this changes is to detach the data from the running instance? Is there another way?
V_PATH=/path/on/my/server/verdaccio; docker run -it --rm --name
verdaccio -p 4873:4873 \
-v $V_PATH/conf:/verdaccio/conf \
-v $V_PATH/storage:/verdaccio/storage \
-v $V_PATH/plugins:/verdaccio/plugins \
verdaccio/verdaccio
However this command would throw
fatal--- cannot open config file /verdaccio/conf/config.yaml: ENOENT: no such file or directory, open '/verdaccio/conf/config.yaml'
You can use docker commit to build a new image based on the container.
A better approach however is to use a Dockerfile that builds an image based on verdaccio/verdaccio with the necessary changes in it. This makes the process easily repeatable (for example if a new version of the base image comes out).
A further option is the use of volumes as you already mentioned.

Docker update Jenkins container to image

I´m using a Docker Jenkins image, but I need to update the current version with some plugins. The idea is use the very same image in an environment where I dont have internet access so there´s no way I can add those plugins, so my idea was create a new image from the current container.
I read that is possible and I follow the steps:
Create new image
sudo docker commit CONTAINER_ID new_image_name
Run new image
sudo docker run --name cutom_image -p 8080:8080 -p 50000:50000 -e TERM=xterm -d new_image_name
But then when I connect by ssh to the container of the new updated image I cannot see any new installed plugin.
But when I see the size of the new image I can see that is a little bit bigger, so there´s must be some change.
Any idea what I´m doing wrong?
Regards.
The Jenkins/Jenkins docker image is normally run with:
docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
this will automatically create a 'jenkins_home' volume on docker host, that will survive container stop/restart/deletion.
If you commit the container, you do not commit the volume content associated with it.
Run your new image with the same options as your old image, and you will get back the same content (including the plugins subfolder)

New docker Image from Running container doesnt hold updated values

I have used Jenkins docker image from dockerhub(https://github.com/jenkinsci/docker)
FROM jenkins/jenkins:lts
USER root
ENV http_proxy http://bc-proxy-vip.de.pri.o2.com:8080
ENV https_proxy http://bc-proxy-vip.de.pri.o2.com:8080
RUN apt-get update
RUN apt-get install -y ldap-utils curl wget vim nano sudo
RUN adduser jenkins sudo
User jenkins
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt
EXPOSE 8080
EXPOSE 50000
The docker build command was executed successfully and container also started successfully.
Docker build command :
docker build --no-cache -t myjenkins .
Docker container command :
docker run --net=host --name=my_jenkins -d -p 8080:8080 -p 50000:50000 myjenkins
Then I logged into Jenkins GUI , created a new user and updated the plugins.
Then created a new image using docker commit command. Master Image ID is c068f8d9a060. The newly created docker image ID is de0789b77703
docker commit c052fd7a26b3 almjenkins:version1
root#vagrant-ubuntu-trusty:~/jenkins# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
almjenkins version1 de0789b77703 13 minutes ago 1.04GB
myjenkins latest c068f8d9a060 4 hours ago 1.03GB
I executed docker run command to start the Jenkins from my new image.
docker run --net=host --name=alm_jenkins -d -p 8080:8080 -p 50000:50000 almjenkins:version1
When i accessed the Jenkins GUI, I'm unable to find the updates in new image.
As descibed in the offical docs for docker commit:
The commit operation will not include any data contained in volumes mounted inside the container.
The jenkins_home which holds all the jenkins configuration is declared as a volume in the Dockerfile for jenkins. Thus the commit command won't inlude can configuration (jobs, nodes, plugins ...)
The solution is to build a customized docker image that includes the configuration.
FROM jenkins/jenkins
COPY jobs /usr/share/jenkins/ref/jobs/
RUN /usr/local/bin/install-plugins.sh workflow-aggregator:2.5 ... # Install all the plugins that you need
You can extract the jobs folder from the old container and add it to the new on:
docker cp <container-name>:/var/jenkins_home/jobs jobs

Why can't docker commit a Jenkins container with customized configuration?

I pulled a Jenkins image and launched it. Then I did some configuration on that container. Now I want to save all my configuration into a new image. Below is the command I used:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f214096e4847 jenkins "/bin/tini -- /usr/lo" About an hour ago Up 1 seconds 50000/tcp, 0.0.0.0:8081->8080/tcp ci
From above output, you can see that the jenkins container f214096e4847 is running.
Now I use below command to commit my changes and create a new image:
$ docker commit f214096e4847 my_ci/1.0
sha256:d83801a700c4060326a5209b87281bfb0e93f46207d960038ba2d87628ddb90c
Then I stop the current container and run a new container from my_ci/1.0 image:
$ docker stop f214096e4847
f214096e4847
$ docker run -d --name myci -p 8081:8080 my_ci/1.0
aba1660be200291d499bf00d851a854c724193c0ee2afb3fd318c36320b7637e
But the new container doesn't include any changes I made. It looks like a container got created from original jenkins image. How to persist my data when using docker commit?
EDIT1
I know that I can add a volume to save the configuration data as below:
-v my_path:/var/jenkins_home
But I really want to save it on the docker image. So users don't need to provide the configuration from their host.
It's important to know that this isn't a good approach. As told you in the comments. The recommended way is to mount volumes.
But if you really want your volume in the image I can propose another way. You can create your own image derived from the official image:
Clone the git repo of the original image
git clone https://github.com/jenkinsci/docker.git
This contains the following:
CONTRIBUTING.md Jenkinsfile docker-compose.yml install-plugins.sh jenkins-volume plugins.sh update-official-library.sh
Dockerfile README.md init.groovy jenkins-support jenkins.sh tests weekly.sh
You just need to make one edit in the Dockerfile. Replace the VOLUME by a mkdir command
# Jenkins home directory is a volume, so configuration and build history
# can be persisted and survive image upgrades
#VOLUME /var/jenkins_home
RUN mkdir -p /var/jenkins_home
Rebuild your own image:
docker build -t my-jenkins:1.0
Start your own jenkins + install some plugins + create some jobs.
docker run -d -p 8080:8080 -p 50000:50000 my-jenkins:1.0
When you're ready with creating the desired jobs you can commit the container as an image.
docker commit 30c5889032a8 my-jenkins-for-developers:1.0
This newest jenkins container will contain your plugins + jobs by default.
docker run -d -p 8080:8080 -p 50000:50000 my-jenkins-for-developers:1.0
This will work in your case. But as I said. It's not recommended. It makes your content dependent of the image. So it's more difficult when you want to perform updates. Also your image can be too big (size).

Resources