Marcus Anthony
Marcus Anthony

Reputation: 99

How do I setup Google VM container configuration for a custom docker run command?

To run my docker image locally, I use:

docker run --rm -d -p 80:80 mkdocs:latest nginx -g 'daemon off;'

My problem is: When setting up a Google Cloud VM using this docker image (in Artifact Registry), how do I setup the COMMAND/ARG parts? I'm very new to the whole Google Cloud VM and container stuffs.

I read the docker/gcloud docs and looks like everything before the container image name (nginx) is just an OPTION, not a COMMAND or ARG. However the whole thing really confuses me a lot. I tried a few times:

  1. Using the whole docker run --rm -d -p 80:80 mkdocs:latest nginx -g 'daemon off;' as COMMAND, doesn't work

  2. Creating a few ARGs such as nginx -g 'daemon off;', but then I have no idea how to pass mkdocs:latest and -d, -p 80:80 to it. Doesn't work anyway.

I also tried to ssh into the VM but it does not connect.

Here is the dockerfile:

# MkDocs container
FROM python:3-alpine AS build-env

RUN apk add bash
RUN apk add --no-cache make cmake
ENV PATH="${PATH}:/usr/src/mkdocs/.local/bin"

RUN pip install --upgrade pip
RUN pip install pymdown-extensions \
&& pip install mkdocs \
&& pip install mkdocs-techdocs-core \
&& pip install mkdocs-material \
&& pip install mkdocs-rtd-dropdown \
&& pip install mkdocs-git-revision-date-plugin \
&& pip install mkdocs-git-revision-date-localized-plugin \
&& pip install mkdocs-redirects \
&& pip install mkdocs-video

ENV PATH="${PATH}:/usr/src/mkdocs/.local/bin"
RUN mkdir -p /home/mkdocs/
WORKDIR /home/mkdocs/
# Added for cloud run
COPY . .
RUN mkdocs build
WORKDIR /
ENTRYPOINT ["/usr/src/mkdocs/.local/bin/mkdocs"]

# Nginx container
FROM nginx:1.21.6-alpine
RUN apk add bash
EXPOSE 80

ENV USER=myuser
ENV UID=7579
ENV GID=7579

RUN addgroup --gid "$GID" "$USER" && adduser --disabled-password --gecos "" --home "$(pwd)" --ingroup "$USER" --no-create-home --uid "$UID" -G "$USER" "$USER"

RUN cat /etc/nginx/nginx.conf
COPY nginx.conf /etc/nginx/nginx.conf

WORKDIR /
RUN mkdir -p /home/mkdocs
COPY --from=build-env /home/mkdocs/site/ /home/mkdocs/
RUN mv /home/mkdocs/* /usr/share/nginx/html/
RUN chown nginx:nginx /usr/share/nginx/html/*

RUN mkdir /tmp/nginx && chown nginx:nginx /tmp/nginx

USER nginx:nginx

Upvotes: 0

Views: 129

Answers (1)

Marcus Anthony
Marcus Anthony

Reputation: 99

OK I figured that out.

Basically I completely misunderstood the concept of containers running on Google VM. I was using Cloud Run before so I could pass arguments to gcloud run deploy. However, a VM is simply a machine instance and it does not magically run docker run for me.

I actually know about this but somehow the "Build a VM based on a docker image" confused me and I thought it was a concept close to Cloud Run so I was searching the answer to run my docker run command. Turns out it is just as easy as ssh into it and run the command manually. I bet there is an automated version for this but so far it's good enough for me.

Upvotes: 1

Related Questions