How can I run a full OS in a Docker container, without specifying a command?

I'm following the CoreOS Docker Documentation and it mentions starting containers with commands like:

docker run someImageName /bin/somebinary

Where someImageName is an image. When /bin/somebinary exits, the image will no longer be running.

I would simply like to run an image, without specifying any binaries to run. Instead, I simply want to run the services (eg, systemd / sysvinit) that are normally run inside the images OS.

This seems like the most common thing anyone would ever want to do with Docker, but trying to run an image without a command returns:

2014/02/05 14:49:19 Error: create: No command specified

How can I start a Docker container and run a full OS, rather than specifying a command?

As documented here, you simply run /sbin/init as the command just like any other unix booting from single user to multi-user mode.

Containers can be full blown OS's, they just don't have to be (neither do VMs for that matter, it's just more complicated to configure and manage).

I would say the whole point of Docker is to make application containers easy, so that you only have to configure an app, not the whole OS.

Docker is a system for management and deployment of application containers, not operating system containers. It seems as if you're conflating running a docker container with booting an operating system.

Your Docker containers should be single-purpose, very narrowly-scoped applications that can be started with a single command. If you're looking for something more complex than that, then Docker is not the solution you're looking for. In that case, check out KVM, ESXi, OpenVZ, LXD etc.

If you're just looking for how you can specify a default CMD and ENTRYPOINT for your containers, you can do that at build-time using a Dockerfile.

To run a full operating system in a container create the following Dockerfile:

FROM fedora:25

CMD /sbin/init

Then build and start the container and enter a shell inside it to explore the services running inside it:

docker build -t os .
docker run -d --privileged --name os os
docker exec -it os bash

Full systemd services inside the container. Beautiful.

docker pull ubuntu

Just run from the same image as many times as needed. New containers will be created and they can then be started and stoped each one saving its own configuration. For your convenience would be better to give each of your containers a name with "--name".


docker run --name MyContainer1 <ubuntu image>
docker run --name MyContainer2 <ubuntu image>
docker run --name MyContainer3 <ubuntu image>

That's it.

$ docker ps
CONTAINER ID        IMAGE            CREATED          STATUS               NAMES
a7e789711e62        67759a80360c   12 hours ago     Up 2 minutes         MyContainer1
87ae9c5c3f84        67759a80360c   12 hours ago     Up About a minute    MyContainer2
c1524520d864        67759a80360c   12 hours ago     Up About a minute    MyContainer3

After that you have your containers created forever and you can start and stop them like VMs.

docker start MyContainer1

To get in the container and do what you wanna do:

docker exec -it MyContainer1 bash

This is a duplicate of this question lxc - Start full container in Docker? - Stack Overflow

@FredtheMagicWonderDog Not quite, although the answer is the same.