How to adjust docker container run options?

Posted November 24, 2015 87.5k views

Currently the only way that I know that works is to stop the container, then delete the container and create a new one....

This seems completely bonkers…

Surely there is a “proper” way to do the following:

  1. docker run -d –name some-ghost ghost
  2. gah! forgot to expose ports
  3. docker stop some-ghost
  4. docker rm some-ghost
  5. docker run -d –name some-ghost -p 8080:2368 ghost
  6. oh shit i just deleted all my posts… oh right, use a data container
  7. docker stop some-ghost
  8. docker rm some-ghost
  9. docker create -v /var/lib/ghost –name some-data busybox
  10. docker run -d –name some-ghost -p 8080:2368 –volume-from some-data ghost
  11. awesome, its up, now lets see what happens when i restart the host, hmm it didn’t start, oh i need to add a restart policy
  12. docker stop some-ghost
  13. docker rm some-ghost
  14. docker run -d –name some-ghost -p 8080:2368 –volume-from some-data –restart unless-stopped ghost
  15. profit!!

It is not obvious to me, seems like you need to know what you’re doing 100% up front before you even think about issuing a docker run or create command, if you forget an option you need to start again… Surely there is a modify options for container command or something?

edited by asb
1 comment
  • While not directly an answer to your question, I’d suggest looking into Docker Compose to solve the issues you are having (verbosity of the run command).

    Compose abstracts all that verbosity away neatly in a “docker-compose.yml” file and takes the pressure off you to remember the complex tags required for the docker run command.

    Using compose, when you want to spin up a/some container(s), all that you need to do is make sure that your terminal is in the same directory as the docker-compose.yml file and run docker-compose up and you’re good to go. Compose is also nice for directly linking containers together (among several other things).

    Highly recommended.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers


If you’re familiar with python, you may want to look in to DockerMap.

It’s designed to ease quite a bit of the more repetitive actions and allows for updating container options. It does require the use of a DockerFile, though it helps there too. May be worth checking out and tinkering with if you’d like to simplify things a bit!

  • OK thanks for that @jtittle

    Based on DockerMap and what you are saying it seems I am missing a fundamental understanding of what a container is and will go investigate that.

    thanks for the pointer ;)

    • @SoreGums

      No problem :-). Using a DockerFile is a way of making things a little easier so that you’re not constantly issuing the same commands repeatedly.

      Think of a DockerFile sort of like how a ~/.bash_aliases file allows you to create aliases and define functions that can be issued via the CLI to speed up what would otherwise be very repetitive. There’s the initial curve, though afterwards, speed! :-)

      • I don’t think aliases correlates to what I’m doing here…

        The only reason I had to run a bunch of commands is because I didn’t know upfront that I should be aware of a restart policy.
        docker run and docker start are two different things right?
        docker run = create a container and start it.
        docker start = start an existing stopped container.

        All my rambling up in OP was how can modify the existing container to behave differently. Like if all I wanted was for some container “AmazeContainer” that had been running for 10 months with 10 months worth of data in it to simply start every time the host machine restarted, deleting 10 months worth of data to modify the restart policy seems bonkers/highly unproductive. There must be a way to preserve the existing container to update its restart policy…

        • @SoreGums

          Oh I understood, I was more so referencing how simple aliases make day to day management by alleviating repetitive and/or lengthy commands and by offering a solution that simplifies things.

          In comparison, the project referenced makes the day to day management and/or modification of Docker Containers easier.

          The project I mentioned above should be capable of handling what you’re needing :-).

Hey, you tried editing /var/lib/docker/<container_id>config.v2.json and restarting the container? It’s a hacky way but for some changes does the trick

  • Having followed the Docker/Container movement this past year, it is becoming increasingly obvious that one needs to RTFM and play around a lot in a test environment before even thinking of running something they deem “production”. It is a different mindset, where the LAMP stack is pretty much learn as you go (get Linux up, get apache, mysql, php installed, tweak some settings here and there, check the results, ok done, setup a backup script/plan, call it a day), container tech is not so forgiving.

    Took me about 6 attempts to connect two containers together last night without docker-compose. However I’ve got it sorted and have a method that should be pretty much copy/pastable into a Terraform solution.