Commands appended to the end of Docker ‘run’ issues

Docker ‘run’ may not work as you expect.

Starting a Docker Container which has autostart features, such as databases, where the Container automatically starts the database, won’t work if a command is appended to the end of the Docker ‘run’ command that starts the Container. For instance, images from the Postgres Docker site will automatically start the database whenever the Container is started. The command:

sudo docker run -it postgres:9.3 /bin/bash

will start the Container with the image named ‘postgres:9.3’ and put the user into a bash shell which will interact with the Container, but the database will not start. Only the bash shell will run, and this prevents any automatic startup of the database. The solution is to start the Container without any commands on the end:

sudo docker run -it postgres:9.3 # Starts the Container using the postgres:9.3 image. The database is automatically started.

then start another PuTTY (or whatever command line tool you prefer) window, and enter the already running Container via a shell:

sudo docker ps # get the id of the Container

sudo docker exec -it /bin/bash # enter the running container through the bash shell

Now you’re in the container via a bash shell, so you can use psql to manipulate the database

su – postgres # only the postgres user can run psql. Other databases may differ.

psql # this puts you into the psql client, and the command prompt will look like


Now you can manipulate the database via SQL and DDL commands.

Docker has been around for about two years now, and there have been over 100 million downloads of the software. The amount of activity involved is impressive. Blogs, technical websites, etc. are buzzing with activity concerning this product, because the ideas are revolutionary: more bang for the buck as far as spin-up time in a Container vs a VM, the number of Containers that can fit in a metal box vs the number of VMs in the same box, and the ability to put each discreet part of an application into its own Container, to name a few. It’s still not ready for prime time in Production IMHO, but the potential is astounding. We may very well see an explosion of competing products in the coming years, as well as products that enhance or improve Docker and other Container based products. Good times.


0 thoughts on “Problems Adding commands the Docker ‘run’ command”

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts


DevOps for the Large Organization

Implementing DevOps for Large Organizations Thoughts on DevOps for larger teams DevQops dev·qops     \?d?v-,Kops\ : to undertake “DevOps” with particular impetus on Quality Assurance (QA), ideal for the larger organisation with rigorous QA processes Read more...


Deployment Version Control for Release Management and Continuous Delivery

Release Management, cornerstone of Continuous Delivery Deployment Version Control, Critical Release Management feature for Continuous Delivery Release Management is best achieved when the Continuous Delivery process relies on an application release automation (ARA) solution that supports deployment Read more...


Which one is better, Kubernetes or Netflix Eureka?

I have been doing some research on the differences between Netflix’s Eureka and Kubernetes. The main difference that I have found is that Eureka is focused on micro-services from the coding level. You write your Read more...