Reputation: 195
I built a phalcon php image with this Dockerfile
FROM ubuntu:14.04
MAINTAINER betojulio
COPY apache2_evogas.conf /tmp/apache2.conf
RUN apt-get update && apt-get install -y \
apache2 \
php5-dev \
php5-mysql \
libapache2-mod-php5 \
gcc \
libpcre3-dev \
git \
&& rm -rf /var/lib/apt/lists/* \
&& git clone git://github.com/phalcon/cphalcon.git \
&& cd cphalcon/build \
&& ./install \
&& cd /etc/php5/apache2/conf.d \
&& echo 'extension=phalcon.so' > phalcon_php.ini \
&& cp /tmp/apache2.conf /etc/apache2/apache2.conf \
&& a2enmod rewrite
CMD /usr/sbin/apache2ctl -D FOREGROUND
and I create the container running this command line
docker run -d -p 80:80 --name webserver -v /www:/var/www/html betojulio/phalcon_project:1.0
and everything works well.
My question is, after I stop the container how do I restart the same container 'webserver' with the same options '-d -p 80:80 -v /www:/var/www/html' or after stopping the container I have to delete it and create it again?
Thank you in advance.
Upvotes: 8
Views: 7831
Reputation: 77315
Like the other answer said, to start a stopped container, you run:
docker start <container name or id>
If it doesn't stay running, check the logs:
docker logs <container name or id>
If you want the container to restart automatically if it stops for some reason look at docker restart policies.
docker run -d --restart=unless-stopped -p 80:80 --name webserver -v /www:/var/www/html betojulio/phalcon_project:1.0
Also, you might want to change your CMD to the following in your Dockerfile.
CMD ["apache2", "-D", "FOREGROUND"]
Upvotes: 14
Reputation: 195
I have some feedback.
When I run my image with
docker run -d -p 80:80 --name webserver -v /www:/var/www/html betojulio/phalcon_project:1.0
the first time everything works well.
The command running in the container is "/bin/sh -c /usr/sbin". I know this typing 'docker ps'. I can not restart the container because the command that is running.
If I remove 'CMD /usr/sbin/apache2ctl -D FOREGROUND' from the Dockerfile ,build an image and run the container with
docker run -d -p 80:80 --name webserver -v /www:/var/www/html betojulio/phalcon_project:1.0 /usr/sbin/apache2ctl -D FOREGROUND
The command running in the container is /usr/sbin/apache2ctl and after stopping the container I can start it with 'docker start container'
Is this normal or there is a bug?
Upvotes: 0