HowTo:Docker: Difference between revisions

From Computer Science Wiki
Jump to navigation Jump to search
Carnold (talk | contribs)
No edit summary
Carnold (talk | contribs)
Line 44: Line 44:
* '''Optional:''' You can run your docker image locally to make sure it works
* '''Optional:''' You can run your docker image locally to make sure it works
** Example: <code>docker run -it test-chatbot /bin/bash</code>
** Example: <code>docker run -it test-chatbot /bin/bash</code>
* '''Optional:''' Commit and push your Dockerfile up to the git repository.
** Example: <code>git add --all</code>
** Example: <code>git commit -m init</code>
** Example: <code>git push origin main</code>

Revision as of 13:48, 6 November 2023

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.
  • Use a text editor to create a new file called Dockerfile
    • Example: nano Dockerfile
    • Contents:
# 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
  • 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
  • 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