gcloud docker not working on Compute Engine VM - docker

I am trying to get docker images from Container Engine to run on a Compute Engine VM. On my laptop I can run gcloud docker pull gcr.io/projectid/image-tag
I just spun up a Debian VM on Compute Engine, but when I try to run any gcloud docker command I get ERROR: (gcloud.docker) Docker is not installed.
> gcloud --version
Google Cloud SDK 140.0.0
alpha 2017.01.17
beta 2017.01.17
bq 2.0.24
bq-nix 2.0.24
core 2017.01.17
core-nix 2017.01.17
gcloud
gsutil 4.22
gsutil-nix 4.22
> gcloud docker --version
ERROR: (gcloud.docker) Docker is not installed.
https://cloud.google.com/sdk/gcloud/reference/docker makes it seem like gcloud docker should work.
Am I supposed to install docker on the VM before running gcloud docker?

Per intuition i tried to install docker with sudo apt-get install docker, but I was wrong, the actual docker package name is docker.io, so I restarted the process and worked this way:
Install the docker package:
sudo apt-get install docker.io
Test if docker is working
sudo gcloud docker ps
Pull your image from the image repository, e.g. gcr.io. If dont have
a particular tag use the latest one.
sudo gcloud docker -- pull gcr.io/$PROJECT_NAME/$APPLICATION_IMAGE_NAME:latest
Run your image. Remember to specify the port mapping correctly, the first port is the one will be exposed in the GCE instance and the second one is the one exposed internally by the docker container, e.g EXPOSE 8000. For instance in the following example my app is configured to work at the 8000 port but it will be accessed by the public on the default www port, the 80.
sudo docker run -d -p 80:8000 --name=$APPLICATION_IMAGE_NAME \
--restart=always gcr.io/$PROJECT_NAME/$APPLICATION_IMAGE_NAME:latest
The --restart flag will allow this container to be restarted every time the instance restarts
I hope it works for you.

Am I supposed to install docker on the VM before running gcloud docker?
Yes. The error message is telling you that Docker needs to be installed on the machine for gcloud docker to work.
You can either install docker manually on your Debian VM or you can launch a VM that has docker pre-installed onto the machine, such as the Container-Optimized OS from Google.

Related

Can't acces apache on docker from my network

I have this Dockerfile :
FROM ubuntu:20.04
EXPOSE 80
After installing apache2 package in the container I can't acces the default page of apache from the network. Also docker is in a virtual machine with debian 10. If I try the official apache image (https://hub.docker.com/_/httpd) everything works fine but I want to know why installing it manually doesn't work.
To build the container from the image I use this command :
sudo docker run --name ubuntu -p 80:80 -it ubuntu /bin/bash
I have run the exactly same test on my virtual centos machine and found working.
I've build the image using your dockerfile and run apache installation using below command.
docker build -t ubuntu
docker run --name ubuntu -p 80:80 -it ubuntu /bin/bash
and In terminal opened by the above mentioned command, i ran the below command.
apt-get update
apt-get install apache2
service apache2 start
After that opened another ssh terminal keeping the current running as i have not run the Ubuntu container in detached mode and checked by using.
docker ps -a
and found container is running with exposing 0.0.0.0:80 and checked
curl localhost
Please make sure you have not stoped docker container before running curl command or hit in the browser as its not run in detached mode or background.

Does docker pull image in Powershell install on Windows system as well

I executed the, "docker pull nginx" in Windows Powershell.
On pulling it downloads an image which is in a few MB's
I have Windows 10 pro.
Then i ran nginx as below,
"docker run --name mynginx1 -P -d nginx"
Does the pull command also install nginx on my Windows machine as well ?
No - the docker pull command doesn't install anything, it just downloads the docker image locally. After the pull there's no container running on the host (which is actually a VM in Windows - slightly different if you're using docker desktop or docker-machine, but I won't get into the weeds here). The docker run command is what actually runs a container in the docker host.

Starting Tomcat8 in docker doesnt work as in native ubuntu 16.04 environment

Following docker image starts tomcat8 in a fresh ubuntu 16.04 in a virtualbox but doesnt in a docker container. Is this a problem with docker, tomcat or am I missing on something?
Dockerfile:
FROM ubuntu:16.04
RUN apt update
RUN apt install -y openjdk-8-jdk
RUN apt-get install -y tomcat8
CMD service tomcat8 start
I assume that the image is built correctly (docker build command ends without errors)
While running the docker container just connect to it and check its logs:
docker logs <CONTAINER_ID> -f
You should see what happens there and why does tomcat fail to start. Maybe Java is not mapped correctly, maybe the ports are busy (unlikely but who knows).
And maybe tomcat starts correctly but you can't access it from outside because the 8080 port is not exposed / mapped (EXPOSE 8080 in docker file / -p 8080:8080 option while running a docker container)

Dockerized gitlab use host docker to CI

I'm currently learning about gitlab-ci, and deploying.
My gitlab instance runs in a docker container, and I would like to use the host's docker in order to build and deploy an image.
Is there such a way to do this?
Yes. If docker is not installed in the image (the current gitlab/gitlab-ce doesn't have it) you need to extend the image with an installation. E.g.
FROM gitlab/gitlab-ce:8.14.4-ce.0
ENV DOCKER_API_VERSION 1.23
RUN apt-get update && apt-get install -y docker.io
The ENV DOCKER_API_VERSION 1.23 is there to ensure API compatibility between the installations. At the time of writing, you'll receive version 1.12.1 from the apt-get install. If you have the same version on the host, then you can leave out the environment variable. If you have 1.11 on the host, then you'll need it (if you have some other version, you'll get an error message with the version number to use).
Build the image like this
docker build -t myrepo/myorg/mygitlab:8.14.4-ce.0 .
And then run it like this
docker run -d --name gitlab -v /var/run/docker.sock:/var/run/docker.sock myrepo/myorg/mygitlab:8.14.4-ce.0
You'll now have docker available from the container:
docker exec -it gitlab bash
$~ docker ps

OS name for docker images

I am trying to build a new docker image using docker provided base Ubuntu image. I'll be using docker file to run few scripts and install applications on the base image. However my script requirement is that the hostname should remain same. I couldn't find any information on OS names for docker images. Does anybody has an idea that once we add layers to a docker image does the OS name remains same.
You can set the hostname with the -h argument to Docker run, otherwise it gets the short form of the container ID as the hostname:
$ docker run --rm -it debian bash
root#0d36e1b1ac93:/# exit
exit
$ docker run --rm -h myhost -it debian bash
root#myhost:/# exit
exit
As far as I know, you can't tell docker build to use a given hostname, but see Dockerfile HOSTNAME Instruction for docker build like docker run -h.

Resources