1. Run a software into Docker Container
-
Pull the ubuntu image
2. run a container from the ubuntu image 3. install golang inside the container 4. copy file from host machine to docker container-
make a directory in container

-
copy file from host to container

-
Verify the copied file

-
-
run the file

server.go
so Finally we run a software (server.go) into Docker Container.
2. Create a Docker Image from a Running or Stopped Container
When to Use docker commit
- To quickly save changes made inside a container
- For experiments, debugging, or learning purposes
Step to create
1. Commit a Container to an Image
General Syntax : docker commit <container_id_or_name> <image_name>
Example
This command creates a new image named go_server from the current state of the container ed06a473b329 (named my_ubuntu).
2. Verify the Created Image

3. Important Observation
The
go_serverimage is exactly the snapshot of themy_ubuntucontainer at the time of commit.
- All installed packages
- All file changes
- All configurations
Everything is baked into the go_server image.
Limitation of docker commit
Suppose:
- Your application file (e.g.,
server.go) changes
Then you must:
- Run a container again
- Manually edit files
- Reinstall dependencies (Go, libraries)
- Commit the container again
This process is manual, error-prone, and not reproducible.
Recommended Solution: Dockerfile
Instead of using docker commit, use a Dockerfile
Why Dockerfile is Better
| docker commit | Dockerfile |
|---|---|
| Manual process | Automated |
| Not reproducible | Fully reproducible |
| Hard to maintain | Easy to maintain |
| Not version-controlled | Version-controlled |
Using Dockerfile : Run a software into Docker Container
-
Create the Dockerfile
Dockerfile
FROM ubuntu:24.04 RUN apt update RUN apt install -y golang WORKDIR /here COPY ./server.go ./server.goDockerfile Instruction Explanation FROM ubuntu:24.04Sets Ubuntu 24.04 as the base image that provides the Linux environment for the container. RUN apt updateUpdates the system package index so new software can be installed correctly. RUN apt install -y golangInstalls the Go inside the container. The -yflag avoids manual confirmation.WORKDIR /hereCreates (if not exists) and switches to /hereas the default working directory.COPY ./server.go ./server.goCopies server.gofrom the host machine into the container’s working directory. -
Build the Dockerfile and set name

-
Verfiy the image

-
Run the newly build image

-
Verify the output
