Step 1: Sign up for a free Docker account
👉 Create an account:
You can create a free Docker account with your email address or by signing up with your Google or GitHub account. Once you’ve created your account with a unique Docker ID, you can access all Docker products, including Docker Hub. With Docker Hub, you can access repositories and explore images that are available from the community and verified publishers.
A Docker ID grants you access to Docker Hub repositories and lets you explore available images from the community and verified publishers. You also need a Docker ID to share images on Docker Hub.
👉 Create a Docker ID:
Go to the Docker sign-up page.
Enter a unique, valid email address.
Enter a username.
(Your Docker ID must be between 4 and 30 characters long, and can only contain numbers and lowercase letters. Once you create your Docker ID you can’t reuse it in the future if you deactivate this account.)
Enter a password that’s at least 9 characters long.
Select Sign Up.
(Docker sends a verification email to the address you provided.)
Verify your email address to complete the registration process.
👉 Sign up with Google or GitHub
To sign up with your social provider, make sure you verify your email address with your provider before you begin.
Go to the Docker sign-up page.
Select your social provider, Google or GitHub.
Select the social account you want to link to your Docker account.
Select Authorize Docker to allow Docker to access your social account information and be re-routed to the sign-up page.
Enter a username.
(Your Docker ID must be between 4 and 30 characters long, and can only contain numbers and lowercase letters. Once you create your Docker ID you can’t reuse it in the future if you deactivate this account.)
Select Sign up.
Once you register and verify your Docker ID email address, you can sign in to your Docker account. You can sign in with your email address (or username) and password. Or, you can sign in with your social provider.
Step 2: Create your first repository
To create a repository:
Sign in to Docker Hub.
On the Repositories page, select Create repository.
Name it <your-username>/my-private-repo.
Set the visibility to Private.
Select Create.
You’ve created your first repository.
Step 3: Download and install Docker
You need to download Docker to build, push, and pull container images.
Step 4: Pull and run a container image from Docker Hub
👉 In your terminal, run docker pull hello-world
to pull the image from Docker Hub. You should see output similar to:
$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:7d246653d0511db2a6b2e0436cfd0e52ac8c066000264b3ce63331ac66dca625
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
👉 Run docker run hello-world
to run the image locally. You should see output similar to:
$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent
it to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Step 5: Build and push a container image to Docker Hub from your computer
👉 Start by creating a Dockerfile to specify your application as shown below:
# syntax=docker/dockerfile:1
FROM busybox
CMD echo "Hello world! This is my first Docker image."
This Dockerfile:
Uses the
busybox
base image (a small, efficient Linux distribution).Specifies a command (
CMD
) to print "Hello world! This is my first Docker image."
👉 To build your Docker image, run the following command in the directory containing your Dockerfile
:
$ docker build -t <your_username>/my-private-repo .
Replace <your_username>
with your actual Docker Hub username. Here’s a breakdown of what this command does:
docker build
: Instructs Docker to build an image from a Dockerfile.-t <your_username>/my-private-repo
: Tags the image with the name<your_username>/my-private-repo
, which allows Docker to reference it more easily..
: Specifies the build context as the current directory (where the Dockerfile is located).
👉 To test your Docker image locally, run the following command:
$ docker run <your_username>/my-private-repo
Replace <your_username>
with your Docker Hub username. This command will start a container from your newly built image and execute any commands defined in the Dockerfile.
👉 You run the command to push your Docker image to Docker Hub, use:
$ docker push <your_username>/my-private-repo
Replace <your_username>
with your Docker Hub username.
You should see output similar to:
cat > Dockerfile <<EOF
FROM busybox
CMD echo "Hello world! This is my first Docker image."
EOF
docker build -t mobythewhale/my-private-repo .
[+] Building 1.2s (5/5) FINISHED
=> [internal] load build definition from Dockerfile
=> => transferring dockerfile: 110B
=> [internal] load .dockerignore
=> => transferring context: 2B
=> [internal] load metadata for docker.io/library/busybox:latest
=> CACHED [1/1] FROM docker.io/library/busybox@sha256:a9286defaba7n3a519
=> exporting to image
=> => exporting layers
=> => writing image sha256:dcdb1fd928bf257bfc0122ea47accd911a3a386ce618
=> => naming to docker.io/mobythewhale/my-private-repo
docker run mobythewhale/my-private-repo
Hello world! This is my first Docker image.
docker push mobythewhale/my-private-repo
The push refers to repository [docker.io/mobythewhale/my-private-repo]
d2421964bad1: Layer already exists
latest: digest: sha256:7604fbf8eeb03d866fd005fa95cdbb802274bf9fa51f7dafba6658294
efa9baa size: 526
👉 Your repository in Docker Hub should now display a new latest
tag under Tags:
You’ve successfully:
Signed up for a Docker account
Created your first repository
Pulled an existing container image from Docker Hub
Built your own container image on your computer
Pushed it successfully to Docker Hub