Error Response Contrainer is not running - hyperledger-fabric

I am trying to Create and Join channel by entering into cli container using command : docker exec -it cli bash
But, i am getting following error response :
Error Response from daemon : Container dasdjha343343xxxxx is not running.

First stop all your running containers and remove them, try to rerun the exact container, and lastly, when you try to bash to explicit container on Windows.10 use $winpty
$docker stop $(docker ps -a -q)
$docker ps -qa|xargs docker rm
$cd fabric-samples/first-network
$docker-compose -f docker-compose-cli.yaml up -d
$winpty docker exec -it cli bash

In your working folder, update to latest version by:
$ git clone https://github.com/hyperledger/fabric-samples.git
Newer version should resolve this issue.

Related

Docker container don't start

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>.

docker logs doesn't log detached exec

My Dockerfile is
FROM node:4
RUN npm install -g yarn
WORKDIR /app
I run docker run -d and mount my current working directory as a volume. All the deps are installed by yarn. I have a npm script to lint the files.
If I do docker exec -it [container] npm run lint it works as expected and I can see all the logs. But if I do docker exec -itd [container] npm run lint, it exits immediately which is expected. But I can't see the logs by running docker logs [container]. How do I reattach the exec or just see to the logs?
I tried docker attach [container] it goes to the repl of nodejs. Why is that?
As mentioned in "Docker look at the log of an exited container", you can use docker logs
docker logs -t <container>
That will show stdout/stderr (with timestamps because of the -t option).
For that last 50 lines of those logs:
docker logs -t <container id> | tail -n 50
Note: that would work only if npm run lint is run by your container (docker run <image> npm run lint)
If your docker exec exits immediately, then yes, there would be no logs produces by the container itself.

Can not see files from Docker in Zeppelin

I'm using Docker for a course about Spark.
I've set up my environment like this:
docker pull bigdatauniversity/spark2
docker run -it --name bdu_spark2 -P -p 4040:4040 -p 4041:4041 -p 8080:8080 -p 8081:8081 bigdatauniversity/spark2:latest /etc/bootstrap.sh -bash
Then I exited Docker and ran this:
docker start bdu_spark2
docker attach bdu_spark2
Now, when I go into Zeppelin I can't find the files given for the course.
I tried finding out if there is another Zeppelin process running at another port so I ran in the Docker console:
docker ps
However, the command docker is not recognised:
bash: docker: command not found
I also tried running docker exec -it docker ps but I got the same result.
So how can I see the files from the Docker container in Zeppelin?

How to stop running node in docker

I have just installed dockers and installed node.
I am able to run a basic express site. My issue now is I can't stop it. Control-C is not doing anything.
Temporarily what I did to exit was:
Close the docker's terminal.
Open a new one.
Search for all docker containers that is running.
Then docker stop [container]
Is this the proper way?
As described here: github: docker-node best practice
You can add the --init flag to your docker run command.
docker run -it --init -p 3000:3000 --name nodetest mynodeimage
I don't know if this is too late. But the correct way to do this is to catch the SIGINT (interrupt signal in your javascript).
var process = require('process')
process.on('SIGINT', () => {
console.info("Interrupted")
process.exit(0)
})
This should do the trick when you press Ctrl+C
I came across this same problem today, and struggled to find an explanation/solution. I discovered (through trial and error) that this only occurs when the CMD in the Dockerfile is set to:
CMD [ "node", "server.js" ]
However, Ctrl+C works fine when the CMD is changed to:
CMD [ "npm", "start" ]
The npm start script in my package.json file is set to node server.js, so I have no idea why this change works, but hopefully this helps.
A docker run should have gave you back the prompt, avoiding the need for CTRL+C, or closing the docker terminal.
Once you log back in that terminal, a docker ps -a + docker stop should be enough to make your container exit (you still need to remove it before trying to launch it again)
If you just want to stop node without stopping the container, you could go inside the container and run:
$ ps aux | grep node #to obtain process ID (value in second column)
$ kill <process ID>
As a part of solution, you can open your package.js and add 3 new commands/scripts :
"scripts": {
"docker-build-and-run": "docker build -t image-dev-local . && docker run -p 3001:3001 --name container-dev-local image-dev-local",
"docker-stop-and-clear": "(docker stop container-dev-local || true) && (docker rm container-dev-local || true)",
"docker-run": "npm run docker-stop-and-clear && npm run docker-build-and-run"
}
and just simply run in the terminal :
npm run docker-run
to up your app on 3001 port in docker and have fun. Every next run will clear previous and build/run again.
To stop and delete it, just run :
npm run docker-stop-and-clear
docker stop <containerName/containerId>
docker kill --signal=SIGINT <containerName/containerId>
docker rm -f <containerName/containerId>
From what I can gather you need both -t and -i for Ctrl-C to work as expected. Command like this would be helpful i believe.
Simple example which i can think of this below
Case 1 to retain container:
$ ID=$(sudo docker run -t -d ubuntu /usr/bin/top -b)
$ sudo docker attach $ID
Control-C
$ sudo docker ps
Case 2 to terminate the container:
$ ID=$(sudo docker run -t -i -d ubuntu /usr/bin/top -b)
$ sudo docker attach $ID
Control-C
$ sudo docker ps
The solution is to use in the Dockerfile this command for starting the application
CMD ["/bin/sh", "-c", "node app.js"]
then we can listen in the app.js with
process.on('SIGTERM', () => {
console.log('SIGTERM received, shutting down...');
});
and we have to run the dockerfile with the --init flag
docker run --init -p 3000:3000 --name nodetest mynodeimage
or we can add in docker-compose beginning from version 3.7 the entry
init: true
to the desired service.
For the app to receive the signal you should use docker stop nodetest or docker-compose down. Shutting down with Ctrl+C does not send the SIGTERM signal.
Inside the node console, after running docker run -it node,
you can exit with the following:
Enter .exit
Press two times
ctrl+c
ctrl+d
If the node container is started in detached mode docker run -d node,
you can stop it with docker stop <CONTAINER_ID or CONTAINER_NAME>.
For example, assuming you want to kill the newest node container:
docker stop $(docker ps | grep node | awk 'NR == 1 { print $1}')

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