how to start the container automatically when its stopped?--AWS - linux

I have the docker container with jar file to run and i run the container by
sudo docker run --name xxx -d imagename
after the jar file was run successfully,then the container became inactive condition.
I want to restart the container automatically in amazon web service .

Have a look at the restart policies Docker provides. Maybe that is the solution for you?
Docker Restart Policies

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

Volume on Docker Swarm is not persistent?

I just want to create a service on Docker Swarm with NGINX and to make data persistent after docker-machine reboot.
I check the manager IP
docker-machine ip manager
Then I go to the machine
docker-machine ssh manager
Inside a Docker Machine I create a new service:
docker service create -p 80:80 --mount type=volume,target=/usr/share/nginx/html --name nginx nginx
Here I expect to have a service running with NGINX on the port 80 with an unnamed volume.
In a web browser I see that NGINX is online at MANAGER_IP:80.
With docker inspect CONTAINER_ID can find the path to the volume and to modify e.g. index.html.
But after docker-machine stop and docker-machine start my change disappears.
Why? What do I have to do to make it persistent (to be available after rebooting docker-machine) ?
Any advice much appreciated.
can you try this
docker service create -p 80:80 --mount type=volume,source=myvolume,destination=/usr/share/nginx/html --name nginx nginx
You just didn't mention the source in your command

Starting multiple services inside Docker container

In my Dockerfile, I have the following:
# Start app and proxy
CMD service nginx start
CMD ["nodejs", "/src/index.js"]
Doing it this way, the Node server is running, but not nginx. Likewise, if I do something like:
# Start app and proxy
CMD service nginx start && nodejs /src/index.js
then nginx is running, but not Node.
Am I overlooking something obvious?
I think you can split your problem with docker-compose.
You will get one container with your nginx image and one container app with your node application.
Then just run a docker-compose up
You can use Docker legacy linking:
In nginx folder docker build -t docker-nginx .
In node folder docker build -t docker-node .
docker run -d --name app docker-node
docker run -d --name nginx --link app:app docker-nginx
Then you point to app in nginx config file. Like app:3000
You could also use docker-compose which would simplify image building and container running. Checkout documentation.

How to launch a Docker container that i've got from another person?

I am a Docker-newbie and I've got a project from another developer including a Dockerfile. This shall give me the Virtual Machine to continue work with the (nodeJS-) project inside this project folder.
Docker is already installed on my machine.
How can I launch this container now?
I've read about a command
sudo docker run -name my_first_instance
but i can't find any container name in the Dockerfile.
The dockerfile will create an image for you that you can launch containers from. this being said , Follow this:
Create a folder.
Copy dockerfile in the folder
cd into the folder execute the following command:
docker build -t <your desired image name> .
This will create an image using directives in the dockerfile in the current folder.
Now launch a container from the image.
docker run -d --name <your container name> <imagename from previous step> <optional startup commands>
Useful docker commands:
You can expose ports in the previous command using -p switch.
You can list Images via docker images
You can list running containers via docker ps
you can list running + exited containers via docker ps -a
have a look at
https://hub.docker.com/_/node/
it is the official repository for NodeJS docker images
If you want some docker images based on NodeJS, you will need to pull them docker pull my_node_image
Then you can launch one with such a command
docker run -it --rm --name my-running-script -v "$PWD":/usr/src/app -w /usr/src/app node:4 node your-daemon-or-script.js
The Dockerfile is just the recipe to build a docker image, for Nginx, Mysql, MongoDb, Redis, Wordpress, Spotify, atop, htop...
If docker images shows nothing, it means you have not yet pulled any docker image.

Docker volumes-from not working when launching container with -H host flat

Looking at shipyard, I noticed that the deploy container launches containers on the host ( redis, router, database, load balancer, shipyard)
This is done by using the -H flag.
So I decided to try this to deploy my apps as this would make deployment tons easier ( versus systemd, init.d ).
I was able to get about 70% there, but the thing that broke was --volumes-from tag.
The container starts, but the volume it's mounting to is empty. I have a simple example posted here.
http://goo.gl/a558XL
If you run these commands on host. it works fine.
on_host$ docker run --name data joshuacalloway/data
on_host$ docker run --volumes-from data ubuntu cat /data/hello.txt
However if you do this in a container. It is broken.
on_host$ docker run -it --entrypoint=/bin/bash -v /var/run/docker.sock:/var/run/docker.sock joshuacalloway/deploy -s
in_container:/# docker ps -----> this shows docker processes on the host
in_container:/# docker rm data ---> this removes docker container data that was created above
in_container:/# docker run --name data joshuacalloway/data
in_container:/# docker run --volumes-from data ubuntu cat /data/hello.txt

Resources