We use docker containers for CI/CD build purposes at work. We had an instance recently where our container needed some added applications in order to publish the build artifacts up and out to a web server for future download. Here is how we went about updating our docker container.
To start I logged into the container VM using Putty. Could do this with console (vmware) or via SSH.
List images on the machine to find the image you want to edit.
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sphinx_base_2 latest 77af0a8bf8bd 45 hours ago 951MB
<none> <none> 83eba990b65c 46 hours ago 946MB
gitlab/gitlab-runner-helper x86_64-943fc252 9996479d93d9 4 months ago 66.8MB
gitlab/gitlab-runner-helper x86_64-6214287e c463142b7af1 11 months ago 57.2MB
sphinx_base_1 latest b14e6de4b12a 13 months ago 840MB
gitlab/gitlab-runner-helper x86_64-c5874a4b fdd135c22836 13 months ago 57.6MB
alpine latest f70734b6a266 13 months ago 5.61MB
Start up a new container with the image we want to update.
docker run -d -it sphinx_base_2
List the running containers
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c6c9b2cf63f9 sphinx_base_2 "/bin/sh" 38 seconds ago Up 37 seconds admiring_kilby
Log into the console for that container. This example is for Alpine Linux.
docker exec -it c6c9b2cf63f9 /bin/sh
Install the apps using the package manager. This example is for Alpine Linux. Notice how the console changes to indicate that we are working inside the container.
/ # apk add openssh sshpass rsync
Test out the app’s functionality in the running container.
/ # rsync test example
If everything checks out commit the changes to the image. You can commit to the same image name (copies overtop) or to a new image name (version control).
docker commit c6c9b2cf63f9 sphinx_base_2
That is the quick synopsis for modifying a docker container.