Sign inGet started
← Back to all guides

How to run your first Docker container

By Deepnote team

Updated on November 23, 2023

A beginner's guide to Docker, detailing the steps to set up and run your first container.

Today, we'll learn how to get started with Docker by running our very first container.

How to run a Docker container

To kick things off, let's run a simple Docker container:

docker run --rm hello-world

Great work! You've just run your first Docker container. Here's what happened with the docker run command:

  1. The run command creates a new container and starts it.
  2. The --rm flag is optional and ensures the container gets removed automatically after it stops.
  3. The hello-world is the image Docker uses as the foundation for the container.
  4. The container runs, outputs a greeting, and then exits.

How to run a website in a Docker container

Starting with hello-world was easy. Now let's run a container that serves a simple website:

docker run --detach --name whoa --publish 80:8080 rackerlabs/whoa

We introduced a few new flags this time:

  • --name whoa assigns a name to our container, expanding the standard auto-generated ID.
  • --detach keeps the container running in the background.
  • --publish 80:8080 maps port 8080 inside the container to port 80 on your host machine.

Now, to get details on your running container:

docker ps --filter="name=whoa"

The docker ps command, akin to the traditional ps, displays information about running containers:

  • --filter="name=whoa" narrows down the output to our specific container.

Take note of the information provided:

  • Container Id - Unique identifier for the container.
  • Image - Image name the container is based on.
  • Command - The command that the container runs on startup.
  • Created - Time since the container's creation.
  • Status - Running state of the container.
  • Ports - Exposed ports, in this case, port 80.
  • Names - Name(s) of the container.

With the container up, use this shortcut command to build a URL to your hosted website:

echo http://$(docker port whoa 8080)

Click the printed link to check out your new website!

Cleaning up

Once you're done with the whoa container, remove it to release the used ports:

docker rm --force whoa

The docker rm command deletes containers by name or ID. The --force flag is used to terminate running containers.

By following these steps, you've effectively run and managed your first Docker containers. Keep experimenting by deploying different types of applications and services in containers. It's a useful skill for any data scientist or analyst to provision an environment quickly.

Remember to check out the content source for this guide here and explore similar tutorials to expand your Docker knowledge.

In conclusion, Docker is an invaluable tool for data scientists and engineers, enabling consistent, efficient, and portable workflows. Whether you are building machine learning models, hosting web applications, or running data analyses, Docker can streamline the process and help you focus on the core of your work. Happy containerizing!

Footer

Product

  • Integrations
  • Pricing
  • Documentation
  • Changelog
  • Security

Company

Comparisons

Resources

  • Privacy
  • Terms

© Deepnote