Skip to content
aaboyle878 edited this page Jan 7, 2024 · 11 revisions

Containerisation Process

To containerise the application it required a number of considerations:

  1. The base python image we wish to use to run the app in this case we used the Python:3.8-slim (FROM)
  2. The working directory for the project within the container and ensuring it was there if required (RUN and/or WORKDIR)
  3. Copying the files from the local machine to the container (COPY)
  4. Installing the ODBC driver to ensure the db works correctly (RUN)
  5. Installing pip so that we might be able to use the same to install the packages within the requirements doc (RUN)
  6. Installing the packages within the requirements doc (RUN)
  7. Exposing the port we wish to connect to the container with (EXPOSE)
  8. The command to run at startup within the container to launch our app (CMD)

Docker Commands

After the creation of the Dockerfile for the app we need to run a few additional command to ensure that we can successfully build and run the containerized app the first of which is:
docker build . - this will build the image of our containerised app based on the instructions provided in the docker file however we will not know the name of the image as such we pass it as an argument using the -t flag so the full command would be docker build -t name of the image .
Once we have built the image we may want to test it locally to do this we will run the container and connect via local host on the port we have exposed in the docker file and to do with we use the docker run command with a structure similar to the following:
docker run -p 5000:5000 image name:tag you will notice this has the -p flag passed as a argument this is to specify which port on our local machine maps to which port on the container, you may also notice I have mentioned the structure of the image to be image name:tag in the even you don't know what tag is you can check with the docker images common as it will have the tag listed in the TAGS column or alternatively you can set the tags using the docker tag command
Finally when you are happy with image and sure that everything is working as it should you can push the image to docker hub using the commands:
docker login to login to your own user account
docker push image name:tag to upload the image to you container registry
additionally after using docker rm and docker rmi commands to remover your images and containers accordingly you might use the docker pull command to pull your image from the registry and test again if you wish

Image Information

For the image build for this project the current/ most recent tag is v1 and should be specified when using the docker pull as the docker daemon will not be able to find the image otherwise however if you wish you may build a docker config file to allow you to pull the image without the need to specify tag implicitly additionally as mentioned above for this project to expose the container on a local machine is is advise to use the docker run -p 5000:5000 command for ease of use.

Clone this wiki locally