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.
Use a restart policy. To configure the restart policy for a container, use the --restart flag when using the docker run command. The value of the --restart flag can be any of the following: The following example starts a Redis container and configures it to always restart unless it is explicitly stopped or Docker is restarted.
If you manually stop a container, its restart policy is ignored until the Docker daemon restarts or the container is manually restarted. This is another attempt to prevent a restart loop. Restart policies only apply to containers. Restart policies for swarm services are configured differently.
So if want to have your container running all the time then there should be a foreground process running in your docker. For testing if you run docker run <imageid> echo hi it will return the output means your container is fine.
Always restart the container if it stops. If it is manually stopped, it is restarted only when Docker daemon restarts or the container itself is manually restarted. (See the second bullet listed in restart policy details)
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"]
docker start webserver
That's it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With