Skip to content
Pinter Computing

Knowledge Base for IT Professionals, Teachers, and Astronauts

Pinter Computing

Knowledge Base for IT Professionals, Teachers, and Astronauts

  • Home
  • Programming
  • DevOps
  • Project Management
  • Software and Hardware
  • Miscellaneous
  • Egyebek
  • About
  • Experience
  • Education
  • Contact
  • Home
  • Programming
  • DevOps
  • Project Management
  • Software and Hardware
  • Miscellaneous
  • Egyebek
  • About
  • Experience
  • Education
  • Contact
Close

Search

Home/Knowledge Base/Build a Docker container image for your application
Knowledge Base

Build a Docker container image for your application

By Laszlo Pinter
March 1, 2020 2 Min Read
0

Create the image

A Docker container image is one of the best formats to distribute your application. The container provides an immutable environment, so the application runs the same way on your workstation and on any server.

We will use the simple Go application we have created in the Your first Go application post. In the main application directory open the text editor and create the Dockerfile

code Dockerfile

We will create a multi-stage build script. The advantage is that the final image is very small, as it only contains the compiled Go application, not the source code, not even the Go compiler. Enter the code

FROM golang:alpine as builder

WORKDIR /src

COPY . /src

RUN go build -o myapp cmd/myapp/*

FROM alpine:3.11.3

 WORKDIR /app

 COPY --from=builder /src/myapp /app

 ENTRYPOINT ["/app/myapp"]

Build the image

docker build -t myapp .

Check the image. myapp should be the image on the top

docker images

The output should be something like this

REPOSITORY        TAG        IMAGE ID            CREATED           SIZE
myapp             latest     267e26010d88        2 minutes ago     7.66MB

Run the image to test it.

docker run --rm -it myapp

If you want to run the image with Docker Compose create a compose file

code docker-compose.yml

Enter the code

version: '3'

services:
  myapp:
    image: myapp

Run the image in Docker Compose

docker-compose up

The output should be

Creating network “myapp_default” with the default driver
Creating myapp_myapp_1 … done Attaching to myapp_myapp_1
myapp_1 | Application config
myapp_1 | MyPackage running
myapp_myapp_1 exited with code 0

Runt the image in Docker Swarm

Initialize the Docker Swarm

docker swarm init

Run the container in the swarm

docker stack deploy -c docker-compose.yml myapp

The output should be

Creating network myapp_default
Creating service myapp_myapp

Check if the stack is running

docker stack ls

The output should be

NAME                SERVICES            ORCHESTRATOR
myapp               1                   Swarm

Check if the service is running

docker service ls

Remove the stack

docker stack rm myapp

Tags:

DevOpsDockerGo
Author

Laszlo Pinter

Follow Me
Other Articles
Previous

Could not create an instance of type ‘Microsoft.AspNetCore.Http.HttpContext’

Next

Using the Windows Subsystem for Linux (WSL)

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Last Changes

  • DevOps Engineering part 1. (Mac) - Make your Macintosh easier to use June 25, 2026
  • Japan travel tips June 22, 2026
  • How to stop the rain and snow in Cities: Skylines II June 20, 2026
  • Cities: Skylines II Developer Mode June 20, 2026
  • 'CSII_MANAGEDPATH' has incorrect path(s) when building Cities: Skylines II mod June 20, 2026

Tags

.NET .NETcore 3Dprinting ASP.NET Core AutodeskInventor AWS C# Chef cloud DevOps Docker EntityFramework Games Git Go iOS iPad iPhone iPod Java Kubernetes Linux MacOSX MSSQL MVC Node.js Packer PowerShell Python RDS RightScale Ruby security Splunk TeamCity Terraform TestKitchen Tomcat Ubuntu Vagrant VirtualBox VisualStudio Windows WordPress Xcode

Recent Comments

  • Zengei László on MyHeritage családfa exportálása és küldése emailben
  • Raúl Castillo on DynDns update error
  • MICHAEL on Windows Media Player 12 cannot find the album information
  • Nargis on Configure Epson ET-3850 scanning on Windows 11
  • Venczelné Zemen Erika on Delta S2302 termosztát programozása

–

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Copyright 2026 — Pinter Computing. All rights reserved.