Development Tools Introduction to Docker Building Images Using Dockerfiles The ENTRYPOINT and CMD Instructions

Juliette Tworsey
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,401 Points

Docker course files?

Hi,

Are the course files available for download somewhere?

Also, I am unable to connect to localhost:8080. What could be the issue?

Here is my Dockerfile:

# Base image
FROM ubuntu:latest

# Commands to run to install dependencies
RUN apt-get update -y
RUN apt-get install -y python3

# When you pass commands to the container, what should interpret them
ENTRYPOINT ["python3"]

# Command to run when the container starts
CMD ["app.py"]

# Working directory
WORKDIR /app

# Copy apps from the local folder to the Docker container
COPY app.py app.py
COPY alternate.py alternate.py

# Make port available
EXPOSE 8080

Thanks!

3 Answers

Jared Smith
STAFF
Jared Smith
Treehouse Guest Teacher

Hi Juliette,

Make sure when you run the Docker container, that you pass the -p option with 8080:8080 as the argument, or else Docker will not bind the exposed container port to your computer's interface.

See the docs here: https://docs.docker.com/engine/reference/run/#expose-incoming-ports

Best, Jared

Juliette Tworsey
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,401 Points

Hi Jared,

Thanks for getting back to me!

These are the commands that I am running from my home directory:

docker build -t sample-web-app:1.0 .

docker run -p 8080:8080 sample-web-app

Localhost is (still) refusing to connect and I'm not sure what to do to get it to start.

I had no problem starting a mongod instance (and mongo) from within Docker, but this one is eluding me.

Thanks in advance for any further clues:-)

Yash Gopal
Yash Gopal
4,638 Points

Make sure no other containers are using the same ports? Maybe try stopping all containers and re-running those commands from within the directory that you have the dockerfile / project in.

localhost doesn't work if you are using docker-toolbox on Windows because it has to use Virtualbox. You'll need to use the IP address of the virtual machine docker creates, which is 192.168.99.1. So you would connect using http://192.168.99.1:8080.