Much like VMWare Fusion or Workstation, Docker is a tool to not only deploy containers but also to create new ones. Docker has an command line tool named Docker Compose that uses a file called a Docker file to tell the tool how you want the container image to be built. In this exercise we will build a simple web server container and insert a custom web page into it.
By default docker compose is not installed, run the following command to see
We will install docker compose with a couple of commands. copy and paste the following and press enter
Copy and paste the following and press enter
curl -SL https://github.com/docker/compose/releases/download/v2.6.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
Make the files executable, copy and paste the following and press enter
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
Create a new directory to store our Dockerfile and web page files
Use the vi editor to create the web page file
Once in the vi editor press i on your keyboard to enter insert mode, then copy and paste the below text when you are done press the escape key on your keyboard then hold the shift key and press the z key twice to save it.
<title>Welcome to nginx!</title>
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
<p>If you see this page, the nginx web server container is
Create a Dockerfile with the following command
Once in the vi editor press i on your keyboard to enter insert mode, then copy and paste the below text
FROM nginx:latest COPY index.html /usr/share/nginx/html/index.html
when you are done press the escape key on your keyboard then hold the shift key and press the z key twice to save it.
Build the container with the following command, note that this command always looks for files in your current directory and the -t is to tag the container with the name webserver and don’t forget that trailing period at the end
docker build -t webserver .
Open a web browser to your Photon VM IP address with the following
You have successfully built your first container!
Now let’s go ahead and stop the container before the next lesson, type the following to get the container id
Type the following then copy and paste the container id and press enter
docker stop containerid