Build and Push Images to Docker Hub

First we'll build a container image to push to Docker Hub. In this Lab, we use Snyk's Docker-Goof sample, but you can bring your own container if you're Docker-dexterous.

Step 1: Clone the docker-goof Repository

Clone the Docker Goof repository to your workstation, then change to the top level directory of the app. Don't have Git? You can download the Docker-Goof repo as a Zip file.

git clone https://github.com/snyk/docker-goof && cd docker-goof
# If you forked the repo, clone your fork.

Step 2: Build the docker-goof Docker Image

The Docker Goof repo has many Dockerfiles. You can build some, or all, of them out. We'll focus on one of the available 6 in the instructions, but feel free to play with them all.

First set an Environment Variable for your Docker ID.

# Set an environment variable for your Docker ID
DockerId=<<your_docker_id>>

Now build the docker-goof Docker Image. Your Docker ID will be appended to the Image Tag.

# Build your images with docker build.
docker build -t $DockerId/docker-goof Dockerfile .

The image is now in our local Docker cache. Run docker images to list it out.

docker images

Step 3: Push the Image to Docker Hub

How we'll push the images to Docker Hub. You'll need to authenticate with Docker Hub first.

# Authenticate with Docker Hub if you haven't already
docker login

Once authenticated, push the docker-goof image to Docker Hub.

docker push $DockerId/docker-goof

Step 4: Verify your Images pushed to Docker Hub

Log into Docker Hub and navigate to your repositories to see the freshly-pushed image.

We're now ready to enable Image Vulnerability Scanning for the repository!