Start full container in Docker?

19,142

Solution 1

docker run ubuntu /sbin/init appears to work flawlessly for me with 0.6.6. You won't get a login screen because Docker only manages the process. Instead, you can use docker ps -notrunc to get the full lxc container ID and then use lxc-attach -n <container_id> run bash in that container as root. sshd isn't installed in the container, so you can't ssh to it.

Solution 2

You can use the ubuntu-upstart image:

docker run -t -i ubuntu-upstart:14.04 /sbin/init

Although this solution is unfortunately deprecated, it is good enough if you need a full OS container that 'drives' like a normal Ubuntu 12.04, 14.04 or 14.10 (change the :14.04 bit) system today. If no version is specified it defaults to 14.04. I have not used it heavily, and had some issues installing more complicated packages (e.g. dbus!), but it might work for you.

Alas Ubuntu has switched to systemd in more recent releases. Googling reveals that there seems to be ongoing work to make systemd work in a docker container without requiring elevated privileges, but it does not seem to be quite ready for prime-time. Hopefully it will be ready when 16.04 becomes LTS.

Another option is of course to use phusion/baseimage, but it has it's own approach for starting services. Seems better suited to minimal multi-process containers.

Share:
19,142

Related videos on Youtube

Epeli
Author by

Epeli

I write code and jump.

Updated on May 06, 2020

Comments

  • Epeli
    Epeli about 4 years

    According to this github issue it should be possible to start a full container with Upstart, cron etc. with Docker 0.6 or later but how do I do that?

    I was expecting that

    docker run -t -i ubuntu /sbin/init
    

    would work just like

    lxc-start -n ubuntu /sbin/init
    

    and I would get a login screen, but instead it displays nothing. I also tried to access it using ssh, but no luck. I'm using the default ubuntu image from Docker index.

  • brujoand
    brujoand about 8 years
    Do you have a link to the depreciation of this solution?
  • NeilenMarais
    NeilenMarais about 8 years
    @brujoand It is deprecated in the sense that ubuntu has moved over to using systemd, so the work done to make upstart work in a docker container will not be useful for versions of ubuntu after 14.10.
  • Mahendar Patel
    Mahendar Patel over 6 years
    My current client (at time of writing) uses 14.04 and does not seem to have plans to upgrade until official support ends, so it's not deprecated for me!
  • Johnny Utahh
    Johnny Utahh about 4 years
    My Docker (version 19.03.6) software running on an Ubuntu 18.04.4 host (and running an Ubuntu image/container) appears to revolt against this maneuver, ending in a Freezing execution.. Maybe this is due to modern Docker (we are 6+ years beyond the above post) frowning upon this /sbin/init behavior? As a Docker newbie, I can only speculate.
  • Badr Elmers
    Badr Elmers over 3 years
    nspawn and podman are easier to have Systemd inside container, podman use the same commands as docker so need no learning