Docker Community Forums

Share and learn in the Docker community.

After commit-ing an image docker doesen't starts the container created from that image!


(Giumbai) #1

I modified the ubuntu official image and installed apache2 and laravel and then commited it. Every time I try to run the image it fails (exited 0 and 127, depends of what CMD command I run on commit), I can’t get it to start neither. This is my second try, after I already tried using Dockerfiles. The only problem with Dockerfiles is that I can’t get it to install packages from repo … Is it something that I do wrong or docker is just that buggy? My third try it will maybe be to export ubuntu with the installed packages to a tar archive and then create a docker file that will use the archive.

  docker run -d -p 8080:80 -v $(pwd):/var/www/laravel giumbai/laravel

  docker commit -m "initial commit" -a "Name"  -c "EXPOSE 80" -c "ENV PATH=/usr/bin:/usr/sbin:/usr/local/bin:/root/.composer/vendor/bin" 7127f32ead016f0fdd4f26b4a04a4340e3642395c84ef6846767d89df7c0b35e giumbai/laravel

and

docker commit -m "initial commit" -a "Name" --change="CMD apache" -c "EXPOSE 80" -c "ENV PATH=/usr/bin:/usr/sbin:/usr/local/bin:/root/.composer/vendor/bin"  7127f32ead016f0fdd4f26b4a04a4340e3642395c84ef6846767d89df7c0b35e giumbai/laravel

Changes to original container:

    apt-get install libapache2-mod-php5
    a2enmod rewrite
    curl -sS https://getcomposer.org/installer | php
    mv composer.phar /usr/local/bin/composer
    composer global require "laravel/installer=~1.1"
    apt-get update && apt-get upgrade && apt-get dist-upgrade

    apache > allow override all  and  /var/www/laravel

Docker version 1.8.2, build 0a8c2e3

docker version

  Client:
   Version:      1.8.2
   API version:  1.20
   Go version:   go1.4.2
   Git commit:   0a8c2e3
   Built:        Thu Sep 10 19:20:17 UTC 2015
   OS/Arch:      linux/amd64

  Server:
   Version:      1.8.2
   API version:  1.20
   Go version:   go1.4.2
   Git commit:   0a8c2e3
   Built:        Thu Sep 10 19:20:17 UTC 2015
   OS/Arch:      linux/amd64

docker info

 Containers: 15
 Images: 15
 Storage Driver: btrfs
 Build Version: Btrfs v4.1
 Library Version: 101
 Execution Driver: native-0.2
 Logging Driver: json-file
 Kernel Version: 4.1.10-200.fc22.x86_64
 Operating System: Fedora 22 (Twenty Two)
 CPUs: 4
 Total Memory: 7.69 GiB
 Name: physicalit.karpaten-computers.ro
 ID: WART:PRLN:CFEN:H6SI:7V26:FAWC:CW76:FDMV:JU3G:5RHB:ZGKG:3QZB
 Username: giumbai
 Registry: https://index.docker.io/v1/

uname -r

Linux physicalit.karpaten-computers.ro 4.1.10-200.fc22.x86_64 #1 SMP Mon Oct 5 14:22:49 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Some screenshots: http://imgur.com/a/PKmRZ


(Ranjandas) #2

Hi,

Probably the problem you are facing is because of the CMD you are using. Is apache that you used in the CMD a script or are you calling the apache binary. If its the latter you should consider using apachectl to start the apache process in the container and you should keep it running in the foreground. So you will have to set CMD as shown below.

CMD ["apachectl", "-DFOREGROUND"]

Please let me know if that works.

Also please share the Dockerfile so that we will be able to help you to identify the reason why the package installation is not working for you.

Regards


(Giumbai) #3

##Hi!

Thanks for the fast response!

This is what I get (docker ps -a):

 0496233fce0c        giumbai/laravel     "/bin/sh -c apachectl"   37 seconds ago      Exited (1) 34 seconds ago                 

And I can’t start it neither!


(Ranjandas) #4

Hi,

You should keep apache running in foreground. If you just execute apachectl it will exit with an exit status 1 and as a result the container will stop.

root@37ddbb5caa7b:/# apachectl
Usage: /usr/sbin/apachectl start|stop|restart|graceful|graceful-stop|configtest|status|fullstatus|help
       /usr/sbin/apachectl <apache2 args>
       /usr/sbin/apachectl -h            (for help on <apache2 args>)
root@37ddbb5caa7b:/# echo $?
1
root@37ddbb5caa7b:/#

See the above snippet , this is whats happening with your container. Its doing what its asked to do.

To keep the container running the process thats started with the container should stay without exiting. Thats why I have asked you to use the CMD as shown in my previous answer.

CMD ["apachectl", "-DFOREGROUND"]

Regards


(Giumbai) #5

I understand now, it worked I did it like that:

docker commit -m "initial commit" -a "Name" --change='CMD ["apachectl", "-DFOREGROUND"]' -c "EXPOSE 80" -c "ENV PATH=/usr/bin:/usr/sbin:/usr/local/bin:/root/.composer/vendor/bin"  7127f32ead016f0fdd4f26b4a04a4340e3642395c84ef6846767d89df7c0b35e giumbai/laravel

625e78bb5aa2947d93384575442ffa207c7c9ad18e6423d1bbaf5a26ff96f63b

But I thought of that and I made a script. Why did it not worked with the script but this way did?

Script:

#!/bin/bash
/etc/init.d/apache2 start > /dev/null 2>&1 &

###Thanks for the Help!


(Ranjandas) #6

Hi,

The reason is as follows.

  • The container starts and it executes the script which you have in specified in the .sh file
  • The .sh file executes something ( starts the apache service ) and it exits with an exit status.
  • Container wont care about if the script which it executed started something in the background. For container to stay alive, the script should stay alive in the foreground.

So in our case, apachectl -DFOREGROUND stays in the foreground without existing. Which keeps the container alive. And if due to some reason apachectl dies, the container will also exit.

The above reasons will help you understand why your script didnt work

Regards