Farhan
Farhan

Reputation: 684

how to start a docker container along-with its parameters changed?

I downloaded the official docker httpd container, but by default it maps my port 32770 to its port 80. i want that whenever i start the container, it listens on my port 80 -> 80.

is there any command line argument at docker startup to give or i can hard-coded this mapping in docker?

I tried to run it with "docker run " command , but every time it starts a new instance of it, and i lose my changes that i made to the docker container i want to use. how can i retain the port mapping changes?

Upvotes: 0

Views: 212

Answers (2)

Elton Stoneman
Elton Stoneman

Reputation: 19154

You want to publish the port from the container to the host, as Thilo says the httpd image already exposes port 80 so you can publish it.

This command maps port 80 and runs the web server in the background:

docker run -d -p 80:80 httpd

Now you can browse to http://localhost and see the "It works!" page.

docker run is a shortcut for docker create + docker start, so it always creates a new container from the image. If you want to make changes to a container and preserve them, either use commit or a Dockerfile to create your own image based on httpd - preferably the Dockerfile, because it's easier to manage and automate. Then you'll have a custom website image that will always be the same when you run it.

Upvotes: 3

Titouan Freville
Titouan Freville

Reputation: 477

You should create your own docker image based on the httpd official image. Then expose the port you want to map (EXPOSE 80) https://docs.docker.com/engine/reference/builder/#/expose it should do what you want.

It will give something like :

FROM httpd EXPOSE 80

build : docker build -t test .

run : docker run test :)

Upvotes: 1

Related Questions