Oddbean new post about | logout
 

# Getting started with Docker

## What is Docker?

Docker is a containerization platform for automating the deployment, scaling and management of applications. It provides an easy way to package an application and its dependencies into a container that can be run on any machine that has Docker installed. Containers are isolated from each other and the host system, making it easy to deploy multiple applications on the same machine without worrying about conflicts.

## Installing Docker

Docker can be installed on a variety of operating systems, including Windows, Linux and macOS. The installation process varies depending on your operating system, but you can find detailed instructions on the [Docker website](https://docs.docker.com/get-docker/).

## Running a Docker container

Once Docker is installed, you can run a container by pulling an image from a registry (such as Docker Hub) and running it using the `docker run` command. For example:
```css
$ docker pull nginx
$ docker run -p 80:80 nginx
```
This will pull the latest version of the nginx image from Docker Hub, and start a new container running on port 80. You can then access the nginx web server by visiting `http://localhost` in your browser.

## Building a Docker image

You can also build your own Docker images by creating a `Dockerfile` that specifies the instructions for building the image. For example, here's a simple `Dockerfile` that builds an image based on the latest version of Ubuntu and installs the Apache web server:
```bash
# Use an official Ubuntu image as the base image
FROM ubuntu:latest

# Update the package list and install Apache
RUN apt-get update && apt-get install -y apache2

# Expose port 80 for Apache to listen on
EXPOSE 80

# Start Apache when the container starts
CMD ["apache2", "-D", "FOREVER"]
```
To build an image from a `Dockerfile`, you can use the `docker build` command. For example:
```
$ docker build -t my-apache .
```
This will build an image called `my-apache` based on the instructions in the current directory (`.`). You can then run a container from this image using the `docker run` command, as shown earlier.