In this exercise, you will pull a couple of Docker images and run them as containers.
The first image will be Nginx. Nginx is a free, open-source web server that can also be used as a reverse proxy, load balancer, and HTTP cache.
The second one will be Apache Tomcat, an open-source implementation of Java Serverlet and Java Server Pages technologies.
docker pull nginx
docker images
docker run -d -p 8080:80 --name mynginx nginx
With your browser go to the ip address of your VM and check port 8080
http://<ip address of your VM>:8080
docker ps -a
docker stop mynginx
docker run -it --rm -p 8080:8080 tomcat:8.0
Note that this time your container is running interactively. If you want to stop it press Ctrl+C
With your browser, go to the IP address of your VM using port 8080
docker rm $(docker ps -a -q)
In the second exercise, you will create a new application image. First, you will get the application code, and then, using a Dockerfile, you will create a new image.
git clone https://github.com/carlosalexei/demoapps.git
If you do not have git installed you can navigate to the GitHub Repository and download a ZIP file with the application code.
cd demoapps/HelloWorld
Take a moment to check this is a simple MVC .NET application
# Define base image that includes dev tools
FROM mcr.microsoft.com/dotnet/sdk:6.0 as DevEnv
# Create a folder
WORKDIR /app
# Copy the project file
COPY *.csproj ./
# Restore dotnet libraries for the project
RUN dotnet restore
# Copy all application files
COPY . ./
# Compile project and create production binaries
RUN dotnet publish -c Release -o /app/out
# Download another image with the ASP.NET runtime
FROM mcr.microsoft.com/dotnet/aspnet:6.0
# Copy from the first image (DevEnv) binaries
COPY --from=DevEnv /app/out .
# Define the process to be executed in the container
ENTRYPOINT [ "dotnet", "HelloWorld.dll" ]
docker build -t helloworld:1.0 .
docker run -d -p 8080:80 helloworld:1.0
Go to https://hub.docker.com and Sign up to have your image repository there.
docker tag helloworld:1.0 <<your account>>/helloworld:1.0
e.g., docker tag helloworld:1.0 carlosalexei/helloworld:1.0
To be able to publish your image to the repository, you need to provide the right credentials. Use the following command to provide the name of your docker hub account and password (Created on task 6).
docker login
docker push <<your account>>/helloworld:1.0
Go to https://hub.docker.com and ensure you provide the documentation for people to use your image. They will use:
docker pull <<your account>>/helloworld:1.0