In this lesson, we are going to be looking at how to do following list of tasks:
- Create very basic Node JS express Web App in TypeScript.
- Build custom image of our application.
- Run newly built web app image in a container.
- Access the web app from our host machine.
-
Create Docker image.
$ docker build -t <your_name>/simpleweb .
-
Run Docker image.
$ docker run -p 8080:8080 <your_name>/simpleweb:latest
-
Access Web server.
http://localhost:8080
.
-
You can access directory structure for debugging purpose.
$ docker run -it shawnkoon/simpleweb:latest sh
-
If you know the container id, you can attach into running container.
$ docker exec -it <CONTAINER ID/NAMES> sh
- Order of Dockerfile instructions matter.
- Developer can reduce unnecessary cache busting and re-installing dependencies by separating
COPY
commands. - You have to map ports in order to access port in container application.
WORKDIR
command will set pwd on ANY subsequent container commands. (Even attaching into container).