docker Verified v27.4 Not installed? Containers

Docker / Build Image From Current Directory

Build Image From Current Directory

Build a Docker image from the current directory using the Dockerfile present.

$
Terminal
docker build .

When To Use

When developing a Docker container image based on local project files.

Pro Tip

Optimize layers in your Dockerfile. Cache layers efficiently to improve build times.

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
Sending build context to Docker daemon  3.072kB\nStep 1/5 : FROM ubuntu:latest\n ---> 47b19964fb50\nStep 2/5 : COPY . /app\n ---> 1f25e5f38a3a\nStep 3/5 : RUN make /app\n ---> Running in 123abc456def\nRemoving intermediate container 123abc456def\n ---> 88e237rdssomething\nStep 4/5 : CMD ["/app/myapp"]\n ---> Running in 789xyz123abc\nRemoving intermediate container 789xyz123abc\n ---> 91askdjfklasjd\nSuccessfully built 91askdjfklasjd\nSuccessfully tagged myapp:latest

Anatomy of Output

Understanding the result

Successfully built a1b2c3d4e5f6 Image ID

Unique identifier for the newly created Docker image.

Successfully tagged myimage:latest Image Tag

Tag name assigned to the built image.

Step 1/5 : FROM ubuntu:20.04 Dockerfile Step

Current step in the Dockerfile while building the image.

Power User Variants

Optimized versions

docker build -f Dockerfile.custom .

Specify a custom Dockerfile during the build.

docker build --no-cache .

Force a complete rebuild without cache.

Troubleshooting

Common pitfalls

Error response from daemon: Dockerfile not found

Solution: Ensure a Dockerfile exists in the current directory.

Error processing tar file: malformed tar file

Solution: Check your context for corruption or issues with included files.

Error: No source files were specified

Solution: Specify context or files required for building the image.

Command Breakdown

What each part is doing

docker
Base Command
The executable that performs this operation. Here it runs Docker before the shell applies any redirect operators.

How To Run

Execution path

  1. Step 1

    Run the command: `docker build .`

  2. Step 2

    Verify the image creation with: `docker images | grep myapp`

  3. Step 3

    Check the output for the image 'myapp'.

Alternative Approaches

Comparable commands in other tools

Alternative containers tools for the same job.