-1

I run a container with some parameters in interactive mode.

docker run -i -t --name mycontainer myimage prm1 prm2

ENTERYPOINT is my application which uses parameters.

After the session was finished I'd like to start a new one with new parameters.

docker start mycontainer
docker attach mycontainer

How can I pass new parameters into the new session?

PS: Is it an appropriate scenario for interactive docker-application? Or I should create a new container for each new session?

Dmitry Petrov
  • 1,490
  • 1
  • 19
  • 34
  • Note to moderators: docker questions are 100% on topic on Stack Overflow. You will find thousands of similar questions regarding container and Dockerfile right here, on Stack Overflow. – VonC Jul 24 '16 at 12:53

1 Answers1

1

It is best if you leave your ENTRYPOINT to the default (sh -c or my_application), and use CMD instead for the command parameter

CMD prm1 prm2

That means, by default, a docker run will use prm1 prm2 by default, but you can override them easily by passing new parameter on the next docker run.


That approach (above) is based on running a new container, instead of restarting an "Exited" one.

That is the common practice, as persistent data should be kept in a volume (docker volume create) that you (re-)mount onto the new container (docker run -v)

If you were to restart your container, and benefit from different parameters, then it depends on your application:

  • if said app can read those parameters from environment variables, the new docker update command (PR 15078, still open on issue 22490) does not yet update environment variables (only cpu and memory)
  • if said app can read those from a property file, you could use docker cp to copy to that container an updated version of said property file, with new properties in it.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Let me clarify. The application uses parameters but there are no parameters by default. So, I can easily pass any param when I create container. But it is not clear how to pass new params when I restart (start+attach) container. – Dmitry Petrov Jul 24 '16 at 13:01
  • 1
    @DmitryPetrov you don't need to restart: you just start (run) a new container) – VonC Jul 24 '16 at 13:02
  • @DmitryPetrov " there are no parameters by default." : that is because you are using ENTRYPOINT. If you were using CMD, there would be parameter by default. – VonC Jul 24 '16 at 13:02
  • Got it. I know that this is a common docker practice for long-run daemon application. I'm trying to keep my interactive (not daemon) container for a long time by restarting. – Dmitry Petrov Jul 24 '16 at 13:04
  • Creating a new container is waste of resources for interactive application. But it looks like the best option. – Dmitry Petrov Jul 24 '16 at 13:19
  • @DmitryPetrov with docker cp, you don't have to create a new container, you can simply copy new files to an *existing* container. – VonC Jul 24 '16 at 14:18