Docker container don't start - linux

Hi I've got a problem with docker. I'm using it on s390x Debian, everything was working fine but now i can't start my containers. Old containers are working but when i create new container using for example: docker run ubuntu then i'm trying docker start [CONTAINER] my container don't start. When i use docker ps -a I've got all of my containers, but after when I use docker ps i can't see my new container. As you can see on scr. I created container with name practical_spence and ID 3e8562694e9f but when i use docker start, it's not starting. Please help.

As you do not specify a CMD or entrypoint to run, the default is used which is set to "bash". But you are not running the container in interactive terminal mode, so the bash just exits. Run:
docker run -it ubuntu:latest
to attach the running container to you terminal. Or specify the command you want to run in the container.

You container did start but exit instantly as it has nothing to do. You can start like this docker run -d ubuntu sleep infinity. Then use docker ps to see the running container. You can of course exec into it to do something docker exec -it <container> bash. You can stop it docker stop <container>. Re-start it docker start <container>. Finally delete (stopped) it as you don't need it anymore docker container rm <container>.

Related

Unable To Run Docker In Interactive Mode in Azure (Windows) VM

Trying to learn container (Docker) by running an interactive mode on Azure (windows) VM. The problem is no matter what I've tried I'm stuck with this:
Service 'w3svc' has been stopped
Service 'w3svc' started
Following are info I think are relevant (please correct me if I'm wrong) and things I've tried:
According to Docker Hub here are the requirement to install Docker Desktop on Windows.
I think it meets the requirements:
The Azure (windows) VM is a D4s_v3; the important thing here is that it's a v3 ( that means it supports Hyper-V)
Was able to install Docker Desktop successfully and it's a Windows container:
Was successfully in pulling two Microsoft base images:
Have tried running these commands as Admin either in PowerShell or Command line:
docker run -it 1202696d4a85 cmd
docker run -it microsoft/iis cmd
docker run -it mcr.microsoft.com/windows/servercore/iis cmd
docker run -it 1202696d4a85 --entrypoint cmd
docker run -it microsoft/iis --entrypoint cmd
docker run -it mcr.microsoft.com/windows/servercore/iis --entrypoint cmd
and we're stuck with this:
However, these two commands:
docker run -it 755f6d13fa75 cmd
docker run -it 755f6d13fa75 --entrypoint cmd
we get this error that tells us that the host and container OS are not compatible:
Is this a misleading error? Thought "Windows Sever 2019 DataCenter" is Server Core? And if it's the Desktop Experience it would have specified?
Also, when creating the VM on Azure there's no 'Server Core' option:
So, what do we need to do so that we can run in interactive mode?
TIA!
[Update]
Based on the suggestions below created a new Azure Windows 10 Pro VM.
Ran these two commands:
docker run -it 1202696d4a85 cmd
docker run -it 1202696d4a85 --entrypoint cmd
Same issue.

Can I run docker diff from a container on the same host as the container I want to run the diff on?

I have two containers running on a host. When I'm in container A I want to run a diff on container B compared to it's image to see what has changed in the filesystem. I know this can be ran easily from the host itself, but I'm wondering is there any way of doing this from inside container A, to see the difference on container B?
You can run any docker commands from within container which will communicate with host docker daemon if:
You have access to docker socket inside container
You have docker client inside container
You can achieve first condition by mounting docker socket to container - add following to your docker run call:
-v /var/run/docker.sock:/var/run/docker.sock.
The second condition depends on your docker image.
If you are running bare Ubuntu image you can have shell inside container which will be able to do what you want with following command:
docker run -it -v /var/run/docker.sock:/var/run/docker.sock ubuntu:latest sh -c "apt-get update ; apt-get install docker.io -y ; bash"

Why app in docker container doesn't restart?

I've deployed some docker containers with golang apps. One of them I need to start by this command:
docker run --restart unless-stopped -it myapp /bin/bash
The next step I enter the container and edit some config files, then I run
go build main.go
and ./main
After that I press ctrl+q and leave it out.
Everything works perfectly and all my containers restart perfectly after restarting server. But there is one issue, when myapp container restarts, the golang application doesn't run while container still works. I have to enter this again and run ./main. How can I fixed it?
Dockerfile
FROM golang:1.8
WORKDIR /go/src/app
COPY . .
RUN go-wrapper download # "go get -d -v ./..."
RUN go-wrapper install # "go install -v ./..." RUN ["apt-get","update"]
RUN ["apt-get","install","-y","vim"]
EXPOSE 3000
CMD ["app"]
When you create a container and pass in /bin/bash as the command, that's as far as Docker cares. When the container restarts, it will start up another instance of /bin/bash.
Docker doesn't watch your shell session and see what things you do after it starts the command. If you want to actually run ./main as the command of the container, then you'll need to pass in /go/src/app/main as the command instead of /bin/bash.
Additionally, compiling code is something better done during the image build phase instead of at container runtime.

Docker: Alias command name to run another sibling docker container

I know how to -v the docker socket into a container to make the host's docker daemon available inside a container. Fine.
I have a dockerized application A that can operate on files on the host.
I have another dockerized application B that wants to use that application A to operate on files on the host, but is hardcoded to call /usr/bin/A filename.
How do I alias /usr/bin/A within container B, so that it will call out to the other container, like
docker run -ti --rm A filename
You could just replace /usr/bin/A in container B with a shell script:
#!/bin/sh
docker run -ti --rm A "$#"
You could do this in the image itself (via your Dockerfile), or you could bin-mount the script when you start container B (docker run -v /path/to/my/script:/usr/bin/A ...).
Now you run /usr/bin/A some_filename and it should do the right thing, assuming that you can successfully run docker inside the container.

docker run container, how to rerun

I build container with:
docker build -f Dockerfile.xyz -t dave/xyz .
after that I run docker with:
docker run -it \
--env='LDAP_USER=uid=bot_for_git,ou=bots,dc=company,dc=org' \
--env='LDAP_PASS=' --volume=/srv/docker/xyz/data1:/data \
-p 8010:8010 -p 9989:9989 dave/xyz
and verified that's all ok.
what is next?
My guess, that I should run docker ps, take container id from there, and to run container with the same preferences (environment, port mapping, volumes mapping) I should run:
docker start -a container_id
am I right?
And what about rebuilding image, if change Dockerfile.xyz and rebuild dave/xyz, does container with container_id get
update automatically, or I should repeat docker run -it step?
docker build [...] creates an image. You can see your images with docker images. You may give that image a specific name with the --tag=[...] option:
docker build --tag="superuser/bestimage:latest" .
docker run [...] <imageId> takes that image and starts a container. You can see active containers with docker ps (all with docker ps -a). If you used the tag above, docker run -it superuser/bestimage:latest may be used.
When you rebuild an image, a new image with a new id is created. You may see that through docker images.
does container with container_id get update automatically
No. In order to update your container, you must first remove the container with docker kill <id> and then start a new one with docker run -it <newID>.
Your initial guess
docker start -a container_id
is close but to be able to interact with the container's terminal, include the -i option, as follows:
docker start -ai container_id

Resources