HowTo:Docker
Introduction
This guide will walk you through creating a git repository which gives you a docker registry to host docker images, build a docker image, and push the image up to the registry. The image will be based on the official PHP docker image https://hub.docker.com/_/php , and a copy of Chatbot for College Students app installed https://github.com/AaravRajSIngh/Chatbot You will need access to workstation that has Docker installed. You can SSH to rlogin.cs.vt.edu and build docker images there. This example compliments the CS Launch walkthrough at HowTo:CS Launch which will walk you through hosting this docker image using Computer Science kubernetes cluster.
Create Repository
Computer offers two Gitlab instances: https://git.cs.vt.edu and https://version.cs.vt.edu git.cs.vt.edu is geared toward academic use, and version.cs.vt.edu is for departmental or research use. We will use git.cs.vt.edu for this example.
- Log into https://git.cs.vt.edu using your CS username and password.
- Click on Projects from the menu on the left.
- Click on the New Project button.
- Click on the Create blank project tile.
- Fill in Project name field with a unique name for your docker image project. Example:
chatbot
- Fill in Project URL fields with your own sub path and project slug.
- Select Visibility Level If your project is public then anyone on the Internet will be able to download and use your docker image given the correct URL. If your project is Private or Internal then to use your docker image you need to create and use a deployment token which will be discussed further in this walk through.
- Click on the Create project button.
- A docker image registry is automatically created with your git repository.
- Adding files to this git repository is optional, however you might find it a useful place to store versioned copies of your Docker image creation files.
Create Docker Image
- SSH to rlogin.cs.vt.edu See Howto::Access_rlogin_service Alternatively, you can use any workstation that has Docker installed.
- Optional: Clone your git repository.
- Example:
git clone https://git.cs.vt.edu/carnold/chatbot.git
- Change into the directory
cd chatbot
- Example:
- Use a text editor to create a new file called
Dockerfile
- Example:
nano Dockerfile
- Contents:
- Example:
# Start from Apache based PHP image FROM php:apache # Make sure git command is installed RUN apt-get update && \ apt-get install vim git -y # Install additional PHP modules RUN docker-php-ext-install mysqli pdo pdo_mysql # Download chatbot app RUN cd /var/www/html && \ git clone https://github.com/AaravRajSIngh/Chatbot.git . && \ chmod 600 .git
- Build the docker image and give it a tag for easy identification.
- Example:
docker build . -t test-chatbot
- Example:
- If successful, your image will be built and store locally but is not yet accessible from your registry.
- Optional: You can run your docker image locally to make sure it works
- Example:
docker run -it test-chatbot /bin/bash
- Example:
- Optional: Commit and push your Dockerfile up to the git repository.
- Example:
git add --all
- Example:
git commit -m init
- Example:
git push origin main
- Example:
Push Docker Image to Registry
At this point you should have a built and working docker image that is stored locally. You will need to push the image up to your docker registry to be able to access it from other hosts or clusters.
- Log into your docker registry using the docker command You need to give the docker command the hostname of the registry. If you are using https://git.cs.vt.edu then the hostname is
container.cs.vt.edu
If you are using https://version.cs.vt.edu then the hostname isdocker.cs.vt.edu
- Example:
docker login container.cs.vt.edu
- Example: