0

I have downloaded docker image and run it interactively using -it argument. However there are some applications that are missing and I install them by apt-get. The problem is everytime I exit the session everything I have installed is erased and I have to reinstall it next time. I thought maybe installing applications in a mounted directory using -v option might work, but since there are already some other applications in that directory I thought that might not be the ideal solution. Is there a standard way to save the current session, meaning save the applications that I've installed. What about the changes to the .bashrc and .bash_profile, and similar files. Is there a an elegant way to save them as well?

UPDATE:

This is the session and its container ID, that I would like to re-run. Is there a way to run it interactively again using the container ID?

CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS                       PORTS               NAMES
50e77c283ae9        shogun/shogun-dev         "bash"              24 hours ago        Exited (1) 4 hours ago                           dreamy_fermi

2 Answers 2

2

I see from your issue you have two ways around this:

  • Generate a docker image from a container that has all packages and configurations you need persistent. In this way, you don’t need to install packages and do configurations every time you create a new container
  • Create a custom docker image from Dockerfile with all packages you need to install. When running container, you can map custom files and persistent data store using -v volume.

Let’s use an example to make this clearer.

# docker run -it --name test_con ubuntu:16.04 /bin/bash

I’ll install few packages, namely vim, bash-completion and wget.

root@9c67dc1776cd:/# apt-get update
root@9c67dc1776cd:/# apt-get install vim bash-completion wget

Then create a new docker image from this container, I have named it test_con. For this we’ll use the command option commit.

# docker commit -m "updated packages" test_con ubuntu:v1

If command execution is successful, you should get output similar to this.

sha256:cdf9dc8fe82407b49bae2a2840e7f59706ac84e9f6a0fff55a62afc7dd0db3c3

Confirm if new container was indeed created with this command:

# docker images

Create test container from it and check if wget is present.

# docker run --name test --rm -it ubuntu:v1
root@401345aecec5:/# which wget
/usr/bin/wget

For the second option, you can look at this wiki page on docker commands. This will help you customize your images on initial creation.

1

The whole point of Docker is that it doesn't change. If you want to change it, update the Docker image.

2
  • I've updated the question with the information about the session, in particular the session ID. Is there a way to execute it again? Mar 26, 2018 at 15:29
  • 1
    @AmeerJewdaki It sounds like you could really benefit from going through Docker's walkthrough. There's no shame in it!
    – Alex
    Mar 26, 2018 at 15:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .