Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test the container or image after docker build?

I have the following Dockerfile

############################################################ # Purpose   : Dockerize Django App to be used in AWS EC2 # Django    : 1.8.1 # OS        : Ubuntu 14.04 # WebServer : nginx # Database  : Postgres inside RDS # Python    : 2.7 # VERSION   : 0.1 ############################################################  from ubuntu:14.04  maintainer Kim Stacks, [email protected]  # make sure package repository is up to date run echo "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe" > /etc/apt/sources.list  run apt-get update  # install python  # install nginx 

Inside my VM, I did the following:

docker build -t ubuntu1404/djangoapp . 

It is successful.

What do I do to run the docker image? Where is the image or container?

I have already tried running

docker run ubuntu1404/djangoapp 

Nothing happens.

What I see when I run docker images

root@vagrant-ubuntu-trusty-64:/var/virtual/Apps/DockerFiles/Django27InUbuntu# docker images REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE ubuntu1404/djangoapp   latest              cfb161605c8e        10 minutes ago      198.3 MB ubuntu                 14.04               07f8e8c5e660        10 days ago         188.3 MB hello-world            latest              91c95931e552        3 weeks ago         910 B 

When I run docker ps, nothing shows up

like image 229
Kim Stacks Avatar asked May 11 '15 04:05

Kim Stacks


People also ask

How do I know if my docker container is working?

The operating-system independent way to check whether Docker is running is to ask Docker, using the docker info command. You can also use operating system utilities, such as sudo systemctl is-active docker or sudo status docker or sudo service docker status , or checking the service status using Windows utilities.

How can I check a container image?

The easiest way to list Docker images is to use the “docker images” with no arguments. When using this command, you will be presented with the complete list of Docker images on your system. Alternatively, you can use the “docker image” command with the “ls” argument.

How do I test the contents of docker image?

To analyze a Docker image, simply run dive command with Docker "Image ID". You can get your Docker images' IDs using "sudo docker images" command. Here, ea4c82dcd15a is Docker image id. The Dive command will quickly analyze the given Docker image and display its contents in the Terminal.

Where is docker image after build?

The Docker image you built still resides on your local machine. This means you can't run it on any other machine outside your own—not even in production! To make the Docker image available for use elsewhere, you need to push it to a Docker registry. A Docker registry is where Docker images live.


1 Answers

You have to give a command your container will have to process.

Example : sh

you could try :

docker run -ti yourimage sh 

(-ti is used to keep a terminal open)

If you want to launch a daemon (like a server), you will have to enter something like :

docker run -d yourimage daemontolaunch 

Use docker help run for more options.

You also can set a default behaviour with CMD instruction in your Dockerfile so you won't have to give this command to your container each time you want to run it.

EDIT - about container removing :

Containers and images are different. A container is an instance of an image. You can run several containers from the same image.

The container automatically stops when the process it runs terminates. But the container isn't deleted (just stopped, so you can restart it). But if you want to remove it (removing a container doesn't remove the image) you have two ways to do :

  • automatically removing it at the end of the process by adding --rm option to docker run.

  • Manually removing it by using the docker rm command and giving it the container ID or its name (a container has to be stopped before being removed, use docker stop for this).

A usefull command :

Use docker ps to list containers. -q to display only the container IDs, -a to display even stopped containers.

More here.

EDIT 2:

This could also help you to discover docker if you didn't try it.

like image 106
vmonteco Avatar answered Sep 22 '22 23:09

vmonteco