Unable to start Docker Container in Bluemix - docker

I have created a simple docker file to deploy a war in tomcat
FROM tomcat
ADD your.war /usr/local/tomcat/webapps/
CMD ["catalina.sh", "run"]
I tested locally and works. I tried building the image and pushed it to Bluemix. The docker image got pushed and I can see it in the dashboard, but while trying to start it up (By Clicking on it ), the Vulnerability assessment kicks off and it gives a warning symbol with an Incomplete text and I am unable to proceed further. Need pointers on how to go about this.
Steps followed -
From my local m/c where I have docker running
# docker tag testimagetom registry.ng.bluemix.net/shabsctr/testimagetom:image_tag
# docker push registry.ng.bluemix.net/shabsctr/testimagetom:image_tag
# cf ic run --name shabstrydocker registry.ng.bluemix.net/shabsctr/testimagetom:image_tag

You can build images with DockerFile by cf command. It'll create your image on your bluemix registory.
cf ic build [--tag|-t TAG_NAME] [--no-cache] [--pull] [--quiet] LOCAL_DOCKER_FILE_PATH

Related

Gcloud and docker confusion

I am very lost on the steps with gcloud verse docker. I have some gradle code that built a docker image and I see it in images like so
(base) Deans-MacBook-Pro:stockstuff-all dean$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gcr.io/prod-stock-bot/stockstuff latest b041e2925ee5 27 minutes ago 254MB
I am unclear if I need to run docker push or not or if I can go strait to gcloud run deploy so I try a docker push like so
(base) Deans-MacBook-Pro:stockstuff-all dean$ docker push gcr.io/prod-stockstuff-bot/stockstuff
Using default tag: latest
The push refers to repository [gcr.io/prod-stockstuff-bot/stockstuff]
An image does not exist locally with the tag: gcr.io/prod-stockstuff-bot/stockstuff
I have no idea why it says the image doesn't exist locally when I keep listing the image. I move on to just trying gcloud run deploy like so
(base) Deans-MacBook-Pro:stockstuff-all dean$ gcloud run deploy stockstuff --project prod-stock-bot --region us-west1 --image gcr.io/prod-stockstuff-bot/stockstuff --platform managed
Deploying container to Cloud Run service [stockstuff] in project [prod-stock-bot] region [us-west1]
X Deploying... Image 'gcr.io/prod-stockstuff-bot/stockstuff' not found.
X Creating Revision... Image 'gcr.io/prod-stockstuff-bot/stockstuff' not found.
. Routing traffic...
Deployment failed
ERROR: (gcloud.run.deploy) Image 'gcr.io/prod-stockstuff-bot/stockstuff' not found.
I am doing this all as a playground project and can't seem to even get a cloud run deploy up and running.
I tried the spring example but that didn't even create a docker image and it failed anyways with
ERROR: (gcloud.run.deploy) Missing required argument [--image]: Requires a container image to deploy (e.g. `gcr.io/cloudrun/hello:latest`) if no build source is provided.
This error occurs when an image is not tagged locally/correctly. Steps you can try on your side.
Create image locally with name stockstuff (do not prefix it with gcr and project name while creating).
Tag image with gcr repo detail
$ docker tag stockstuff:latest gcr.io/prod-stockstuff-bot/stockstuff:latest
Check if your image is available in GCR (must see your image here, before deploying on cloudrun).
$ gcloud container images list --repository gcr.io/prod-stockstuff-bot
If you can see your image in list, next you can try to deploy gcloud run with below command (as yours).
gcloud run deploy stockstuff --project prod-stock-bot --region us-west1 --image gcr.io/prod-stockstuff-bot/stockstuff --platform managed
There are 3 contexts that you need to be aware.
Your local station, with your own docker.
The cloud based Google Container Registry: https://console.cloud.google.com/gcr/
Cloud Run product from GCP
So the steps would be:
Build your container either locally or using Cloud Build
Push the container to the GCR registry,
if you built locally
docker tag busybox gcr.io/my-project/busybox
docker push gcr.io/my-project/busybox
Deploy to Cloud Run a container from Google Cloud Repository.
I don't see this image gcr.io/prod-stockstuff-bot/stockstuff when you list images in the local system. You can create a new image by tagging that image with this image gcr.io/prod-stock-bot/stockstuff and re-run the gcloud run command.
for the context I am using Flask (python)
I solved this by
update gcloud-sdk to the latest version
gcloud components update
add .dockerignore, I'm guessing because of the python cache
Dockerfile
README.md
*.pyc
*.pyo
*.pyd
__pycache__
.pytest_cache
expose the port to env $PORT
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 app:app

Created Docker Container process not getting listed

Created Docker container process is not showing using command docker ps --all
I have created only one Dockerfile in a directory, and which is a single available file inside the directory.
the Dockerfile contains following lines:
# Use an existing docker image as a base
FROM alpine
# Download and install a dependency
RUN apk add --update redis
# Tell the image what to do when it starts
# as a container
CMD ["redis-server"]
and after saving the file with name "Dockerfile" and without any extension, I am simply executing the command to build using docker build .
and the logs are as follows:
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM alpine
---> a24bb4013296
Step 2/3 : RUN apk add --update redis
---> Using cache
---> 218559ae3e9b
Step 3/3 : CMD ["redis-server"]
---> Using cache
---> fc607b62e266
Successfully built fc607b62e266
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
so, as above you can see the container image process is getting built successfully, but still the container not getting displayed using docker ps --all command.
Well I am using Windows 10 x64 OS & with assurance that no antivirus or firewall is blocker this docker. Am I missing something or making any mistake here?
docker ps works like the unix command ps. It doesn't show all the docker images that could be run. It only shows the docker containers that are running (or with -a, have been run).
You've built a docker image but you haven't yet run it with docker run.
Try docker run --rm -it fc607b62e266 and if you have everything et up right, it should start up your redis server. (--rm removes the container when it stops running, generally a good practice unless you want it to persist).
You'll see your new image - not container because it hasn't been instantiated yet - in the output of docker images. Add a -t flag to give a tag to your docker build command and you'll see it under that name, otherwise, you can always use the image ref.
A container will only run while it's underlying "root process" is running. When running a service like redis-server, this means the container will run until signaled (docker service restart, system restrart, or docker kill).
While it is running, more processes can be executed within the container with docker exec. Each of these is a separate process, but all will be terminated when the "root process" ends. The converse, of course, is not true - ending the execed process doesn't affect the "root process".

How do I create my docker image from a forked GITHUB repo?

I forked Grafana into my repo and I made some changes to it, I want to test this in docker.
How do I build this as a docker image?
PS: Am new to this.
Thank you
Grafana has a Dockerfile, so you can build a Docker image using that file.
In your forked directory, run the following to build the image.
docker build --tag grafana .
This will create a Docker image named grafana with your changes.
Then follow Grafana's instructions on running from a Docker image:
docker run -d -p 3000:3000 --name grafana-dev grafana
and open localhost:3000 in a browser.
You might consider looking at the documentation for docker run and docker build.

Error building Docker image in Windows 7

New to docker and I'm using Windows 7 SP1. It looks like docker is running fine in my machine as I have tried running hello-world by command docker run hello-world as instructed in the tutorial and got expected result. Now all I'm trying to do is create a docker image for a .net core console app. My app built and ran. but while building docker image by command docker build -t myapp . I get the below error
error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.30/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&c
puquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=
duke&target=&ulimits=null: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on
Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
Below my Dockerfile
FROM microsoft/dotnet:1.1-runtime-nanoserver
WORKDIR /DotNetConsole
COPY /bin/Debug/netcoreapp1.1/publish/ .
ENTRYPOINT ["dotnet", "DotNetConsole.dll"]
I could get around this problem by starting the "Docker QuickStart Terminal" installed with the docker tools, and running the commands for building the docker images from there.
If I used GIT BASH instead of the Docker QuickStart Terminal to execute the commands, I would get this kind of error. So it seems that if the commands are not executed from the Docker terminal itself, these errors show up.

Start up docker container without dockerfile

I've been using Dockerfiles so often that I've forgotten how to start up a new one without one.
I was reading https://docs.docker.com/engine/reference/commandline/start/ and ofc it doesn't state how to start up a new one.
docker run -it ubuntu:16.04 bash
A Dockerfile describes a Docker image not a container.
The container is an instance of this image.
If you want to run a container without building an image (which means without creating a Dockerfile), you need to use an existing image on the Docker Hub (link here).
N.B.: The Docker Hub is a Docker online repository, they are more repositories like Quay, Rancher and others.
For example, if you want to test this, you can use the hello-world image found on the Docker Hub: https://hub.docker.com/_/hello-world/.
According to the documentation, to run a simple hello-world container:
$ docker run hello-world
Source: https://hub.docker.com/_/hello-world/
If you don't have the image locally, Docker will automatically pull it
from the web. If you want to manually pull the image you can run the
following command:
$ docker pull hello-world
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Source: https://hub.docker.com/_/hello-world/
docker start is used to start a stopped container which already exists and in stopped state.
If you want to start a new container use docker run instead. For information about docker run please see https://docs.docker.com/engine/reference/commandline/run/

Resources