Skip to content

Containerization Process

Omar Mokhtar edited this page Jun 15, 2023 · 2 revisions

The Image Creation Process

Using the Dockerfile, It creates an image of the Go application in 2 stages.

Stage 1: Building the Go application

At this stage, I used the golang-alpine as a base image to build the source code.

Stage 2: Creating the Running Image

  • To reduce the image size, I copied the binary to a lightweight base image (alpine).

  • Selected the binary as the entry point of the container at the runtime.

Then created the final image which will could be uploaded to the docker hub.

How to build and run ?

The following command builds the image

$ docker build --tag <app-image-name> .

Now you can run a container instance using this command

Make Sure you have a Mysql database running and replaces the environment variables value in the following line to the values of your database!

$ docker run -d -p <host_port>:9090 -e MYSQL_HOST=<Host> -e MYSQL_USER=<USER> -e MYSQL_PASS=<PASS> -e MYSQL_PORT=<PORT> <app-image-name>

Now you have the container of the server running and you can access it through the localhost:<host_port>

Docker Compose

With the help of the docker-compose you can run the whole application and the MySQL database using one command only.

$ docker-compose up

by running this command, MySQL and the server containers will be created sharing the same network.

compose