-
Notifications
You must be signed in to change notification settings - Fork 0
Containerization Process
Using the Dockerfile
, It creates an image of the Go application in 2 stages.
At this stage, I used the golang-alpine
as a base image to build the source code.
-
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.
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>
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.