Modifying an Existing Docker Image

To install a custom package or modify an existing docker image we need to

1 run a docker a container from the image we wish to modify
2 modify the docker container
3 commit the changes to the container as a docker image
4 test changes made to image

Running a docker container from an image

The command to do this is,

docker run -it yhat/scienceops-python:0.0.2 /bin/bash
  • The -i tells docker to attach stdin to the container
  • The -t tells docker to give us a pseudo-terminal
  • /bin/bash will run a terminal process in your container

Modify the docker container

Once we are in our container we can install package(s), and set environment variables

$ sudo apt-get install vim
$ export AWS_SECRET_KEY=mysecretkey123
$ export AWS_ACCESS_KEY=fooKey

When you are done modifying your container you must exit by running the exit command. Once we exit the container, we need to find the container ID by running

docker ps -a

Commit the changes to the container as a new image

Copy the container ID for the container you just modified, and then run the docker commit command to commit changes to your container as an image.

docker commit [options] [container ID] [repository:tag]

An example docker commit command is the following.

docker commit e8f0671518a2 yhat/scienceops-python:0.0.2

Note here! You must commit the changes with the same tags as the scienceops image on your system. To see your new image run.

docker images

Test changes made to image

To test your changes when adding an environment variable run the test command

$ docker run -it yhat/scienceops-python:0.0.2 echo $AWS_SECRET_KEY