Docker learn issue - docker

I'm learning docker with docker with get-started pages (https://docs.docker.com/get-started/part2/#sample-dockerfile) in official docker site. In part 2 "Build and run your image" i'm trying to run docker container with next command:
docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0
I run command docker ps, and there is no docker running. I tried docker start bb an there is still nothing. I use docker in Ubuntu 20.04 virtual machine. And thus localhost:8000 web page "can't be reached". Docker building was successfull (i got message Successfully tagged bulletinboard:1.0)

Related

Docker - unknown command "run"

I am trying to run a docker container on an Ubuntu WSL2 instance on Windows 10. Docker version installed in 20.10.17. I have been able to run docker commands and build the image successfully.
The output of docker images:
When I try to run the container using the command docker run -p 5000:5000 test it gives the following error:
I have never had this issue with docker before and not sure why it thinks it's an npm command. Does anyone know why this is happening?

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.

Official Docker image says docker not running?

I perform the following docker commands in the following order:
docker pull docker
docker run -ti <imgId>
https://hub.docker.com/_/docker/
Now I am inside the "docker" image for Docker
Now suppose I create a temp folder and download a Dockerfile
mkdir temp
cd temp
curl <dockerfile>
docker build .
It will tell me Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
This means that the docker service needs to be started, but as the official docker image comes on alpine linux, commands like service/systemctl are not available, so we must perform apk add openrc --no-cache to access these.
After I install it, I still cannot start the docker service.
Performing system docker start says that it cannot find docker as a service?
service: service docker does not exist
Eventually I want to build this via Jenkins.
In the build step, I perform Execute Shell
if [ -f "Dockerfile" ]; then
echo "Dockerfile exists ... removing it"
rm Dockerfile
fi
wget <dockerFile url>
docker build .
I purposely don't do the openrc on Jenkins since I want to test locally first
The image you're pulling here (with the latest tag) does not contain the docker daemon. It's meant to be used as the docker client. What you want is to first get the docker daemon running with the image tagged dind (docker in docker).
docker network create dind
docker run --privileged --name docker --network dind -v docker-client-certs:/certs/client -d docker:dind
To verify it started up and works, you can check the logs.
docker logs docker
Now you can use a client container to connect to the daemon. This is how you connect interactively to the shell, like you wanted to:
docker run -ti --network dind -e DOCKER_TLS_CERTDIR=/certs -v docker-client-certs:/certs/client:ro docker
Docker commands should work inside this container. If you do docker version, you should see the versions of both the client and the server.
Note the two containers share the same network (some examples online feature links, but those are deprecated). They also share some of the TLS certs, which are generated when starting up the dind image.

Docker Inside a Docker on Windows

I have seen docker inside docker docker container for Ubuntu/Linux. As per the replies in this thread, the following command works
docker run -v /var/run/docker.sock:/run/docker.sock -v $(which docker):/bin/docker [your image
Are there any similar commands available for docker in Windows 7?
I am using the below command in Windows 10 to run docker inside docker. The docker image is with alpine OS. Note that the path is //var/run/docker.sock
docker run -it --rm --privileged --name dockerindocker -v //var/run/docker.sock:/var/run/docker.sock docker
/ # docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
02285c22006f docker "docker-entrypoint..." 3 seconds ago Up 2 seconds dockerindocker
/ # cat /etc/alpine-release
3.6.2
Unfortunately Windows doesn't support true docker-in-docker yet.
All the answers here are about running a docker client in a container which connects to the top level docker server on the host (same docker running the container where you invoke docker from). It is not a real docker in docker.
See discussion here for more details https://github.com/docker-library/docker/issues/49

Boot2Docker to Google Compute Engine VM: saving Docker container

I am running Boot2Docker v1.0.1 on Windows, and wish to fire up a Docker container I have created on a Google Compute Engine VM.
In order to do so, I need to save the container and upload it to Google Cloud Storage.
I issue the following command:
docker save --output=mycontainer.tar mycontainer:latest
The command completes without error. However, I cannot find the rce_env.tar file anywhere on my hard drive.
Does anyone have any experience with this? If not, is there a better way to run containers on GCE VM's?
You can run google/docker-registry locally to push your container images to GCS.
docker run -ti --name gcloud-config google/cloud-sdk \
gcloud auth login
docker run -ti --volumes-from gcloud-config google/cloud-sdk \
gcloud config set project <project>
docker run -d -e GCS_BUCKET=bucketname -p 5000:5000 \
--volumes-from gcloud-config google/docker-registry
docker tag imagename localhost:5000/imagename
docker push localhost:5000/imagename
And then run it on GCE to pull your containers from GCS.
docker run -d -e GCS_BUCKET=bucketname -p 5000:5000 google/docker-registry
docker run localhost:5000/imagename
I understand that you are using boot2docker on windows.
On a similar setup, using OSX and boot2docker 1.1.0, the following works:
docker save --output mycontainer.tar mycontainer:latest
As also does redirecting standard output:
docker save mycontainer:latest > mycontainer.tar
GCE now allows to store docker images for your projects using the gcloud command.
you can now run $ gcloud preview docker push gcr.io/YOUR-PROJECT/IMAGE-NAME
Source: https://cloud.google.com/tools/container-registry/#pushing_to_the_registry

Resources