How to run a container so that it automatically runs its application

Hi all,

I’m new to Docker and have been learning how to do things the Docker way. I have been practicing with NGINX and I have an image built. I can run the image into a container, but I find NGINX is not running in the container. I have used this command to create my container and expose the ports:

docker run -i -t -d -p:80:80 -p 443:443 --name webcontainer mynginx /bin/bash

I then ‘docker attach webcontainer’ and in the bash prompt type ‘nginx’

This starts nginx and I can see my website. How do I do a docker run so that nginx starts automatically?


docker run -i -t -d -p:80:80 -p 443:443 --name webcontainer mynginx nginx

you also can write your “application” to be started in the CMD section of your Dockerfile.