Skip to content

docker desktop

Dockerfile reference

Commands Descreption
COPY Copy files in to the image
Volume Creates a Mountpoint as defined
ENTRYPOINT The executable that runs when container is run. It accepts input parameters, or takes from CMD
CMD Command to execute at start, will ignore input parameters. If ENTRYPOINT is defined CMD arguments are passed as arguments. Only 1 command allowed, only last one will take effect.
EXPOSE Defines ports to be published.
ENV Variables to be defined in the container.
RUN A command to be run in a new layer of Image being build
FROM Define base image from which image is built. This is first instruction.
WORKDIR Working Directory of container

Difference between CMD and ENTRYPOINT

Both Entry point and CMD execute instructions at start of container, however behaviour differ. CMD : When only CMD is specified, it executes command and will ignore any parameters passed. ENTRYPOINT: Defines command to execute at start, then inputs are passed as arguments. If CMD also specified, ENTRYPOINT will treat CMD as arguments than commands.

Use of CMD is preferred unless there is requirement to accept arguments for container run.

Podman

Build container without Docker (Mac/Linux/Windows)

alt text

Podman is an opensource tool to manage all your container needs without requiring Docker or Docker desktop. It has same command sets as Docker and it does not require Daemon.

- Opensource
- Fast and light
- Secure : Rootless container allow to contain privileges
- Compatible : Supports OCI compliant containers including Docker
Install Podman
brew install podman
# On Mac, each Podman machine is backed by a virtual machine
# After installing, you need to create and start your first Podman machine
podman machine init
podman machine start
podman info
Simple Flask app
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
    return "My flask container"
if __name__ == '__main__':
    app.run()
Prepare Docker file

You can use most Docker commands with podman.

FROM python:3.10-slim
WORKDIR /app
COPY . /app
RUN pip install --trusted-host pypi.python.org Flask
EXPOSE 5000
CMD ["flask", "run", "--host=0.0.0.0"]

Build and run pod
# Build image from FLask App
podman build -t myflask:latest .
# Check your images
podman images
# Run your container
pod podman run localhost/myflask:latest -p 5000:5000
# Verify the site
curl http://localhost:5000/
# Check running containers
podman ps (-a to list all including stopped)

Command references

Commands Descreption
podman ps -a List all containers including stopped
podman run -p 5000:5000 -d Run container in Daemon mode and portforward
podman image tag newtag:version Create new Tag for image
podman image prune -a Delete al the images
podman inspect Inspect a container image
podman container rm -f $(podman container list -aq) Remove all pods including stopped
podman image rm -f $(podman image ls -q) Remove all images from the system