Welcome to my Docker Essentials series, which teaches you the basics you’ll need to know in order to get started with Docker. In this video, we take a look at how to access the application that’s running inside a container by forwarding ports.
Launch an NGINX container
docker run nginx
Note: The container is fairly useless by default, you can’t easily access the app running inside unless you forward the port to a port on the host.
Launch an NGINX container, with port-mapping
This variation of the previous command will also launch an NGINX container, but also map a port inside the container to a port on the host:
docker run -it -d -p 8080:80 nginx
Stop a container
To stop a container, run the following command against its ID:
docker stop <id>
Launch an NGINX container, with port-mapping and auto-restart
The following command is similar to the previous one, but if the container exits for some reason, it will be relaunched:
docker run -d -it --restart unless-stopped -p 8080:80 lltv/apache-test-1:1.0