Howto open ports into your Docker containers | docker ubuntu how to open ports in containters

I’m playing around with docker containers, I just wanted to build a docker container and run a service on it which will be accessible externally.

Lets start by getting a fresh ubuntu image from the repos.

Lets see what images are now available, you should see the latest download in the list.

You see this. We’ll pick the newest one.

Now this is how we select the image and open the ports, see the “-p” switches? This will open SSH (22) and Web (80).

This will build the container, once your at the logon prompt you will need to install the services, ie

This will update apt and install apache and ssh

This will start the services.

This will enable the services to start at startup.

Now the container is setup we can exit out.

Once we have exited we’ll start the container.

Now we need to find out if the container is running, and if its running which random ports its assigned to our services.

That command will display the following.

Now the above output tells us the container is running and it has assigned ports to out services. So if you put up the webbrowser on your computer and put the hosts IP in like this,

Now you should see the apache test page.

or is you want to ssh into the container enter this command

Just name sure you setup a user account on the container first.

Leave a Reply

Your email address will not be published. Required fields are marked *