Logging in to Docker

Webapp.io creates entire VMs as easily as Dockerfiles, so it’s common for our users to use Docker or docker-compose within webapp.io.

Docker hub rate limits requests made by unauthenticated users, so it’s imperative to create a docker hub account and log in to it to avoid failing tests.

The simplest way is to combine SECRET ENV with RUN:

  1. Add a new secret with key “DOCKER_LOGIN” in the secrets pane (the lock icon to the left)
  2. Make the value for that secret be your docker hub login
  3. Press the “Save” button to save the new secret.

Change your Layerfile and add the following lines after installing Docker:

RUN echo "$DOCKER_LOGIN" | docker login --username (INSERT USERNAME) --password-stdin

Full example of Layerfile that installs & runs a docker container, then creates a persistent staging link from it:

FROM vm/ubuntu:18.04

# To note: Layerfiles create entire VMs, *not* containers!

# install the latest version of Docker, as in the official Docker installation tutorial.
RUN apt-get update && \
    apt-get install ca-certificates curl gnupg lsb-release && \
    sudo mkdir -p /etc/apt/keyrings && \
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
    echo \
    "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" |\
    sudo tee /etc/apt/sources.list.d/docker.list > /dev/null && \
    apt-get update && \
    apt-get install docker-ce docker-ce-cli containerd.io

RUN echo "$DOCKER_LOGIN" | docker login --username (INSERT USERNAME) --password-stdin

# copy files from the repository into this staging server
COPY . .

RUN docker build -t image .
RUN docker run -d -p 80:80 image
EXPOSE WEBSITE http://localhost:80