One loop
The loop is: build an image, run a container, open the app, fix errors, rebuild. Your Dockerfile is not proven until the app works from the image on your laptop.
An image is the packaged app. A container is a running copy of that image.
Build the image
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done
docker build -t campus-events .Run a web app
Most web apps listen on a port inside the container. Your browser needs a host port on your laptop mapped to that container port.
This example maps laptop port 3000 to container port 3000. Change the port if your app uses 5000, 8000, or 8080.
docker run --name campus-events-web -p 3000:3000 campus-events
# Then open:
# http://localhost:3000What port mapping means
The left side is the host port. That is the port on your laptop. The right side is the container port. That is where the app listens inside Docker.
If you use -p 8080:3000, you open http://localhost:8080, even though the app inside the container still listens on 3000.
docker run -p 8080:3000 campus-eventsName your container
Use --name while learning. It makes logs and cleanup easier because you do not need to copy a random container ID.
If you run the same name twice, Docker will complain. Remove the old container or choose a new name.
docker logs campus-events-web
docker rm campus-events-webRebuild after changes
Changing your app files does not magically change an image you already built. The image is a snapshot made at build time.
If you edit code, dependencies, or the Dockerfile, build again before you run again.
docker build -t campus-events .
docker run --name campus-events-web -p 3000:3000 campus-eventsDebug first failures
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done
docker logs campus-events-web
docker ps -a
docker rm campus-events-webDo this now
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done
docker build -t your-project-name .
docker run --name your-project-web -p 3000:3000 your-project-name