I did some installations (apache, php, etc) on my container. Now when I start my container it stops right away. No idea how to enter to command line and keep my web server running within that container.
While I’m reading a book I would appreciate if you can give me some hints and directions.
you could do a docker logs YOUR_CONTAINER for your container to see if it logs some errors.
Otherwise you can start your container with a shell by overriding the command docker run -ti YOUR_IMAGE /bin/sh or by overriding the entrypoint docker run -ti --entrypoint /bin/sh YOUR_IMAGE
Thanks. Logs are empty. Anyways when do docker run it just creates another container but I want to start a new container with all layer of modifications.
It is extremely common for containers to exit and be removed, and you should get used to a workflow where local changes inside a container are not persisted.
I’d highly recommend reading the Docker introductory Build your own image tutorial. When you want to run a container with software installed in it, write a Dockerfile to create an image that has that software (or find a prebuilt image with it) and then docker run that image from a known starting point.
Great that you have found your way into the docker community. I just wanted to share some of my experiences and the tips and tricks I received when I started with Docker.
First, and most important: Docker is NOT a virtual machine. Well it is. And it isn’t. Confusing. You can run a Docker container as a full fledged Ubuntu or any other *ux-flavour that you like and I actually does that quite often. But then it is to test commands, scripts or other stuff where I don’t want to mess up other installations or environments. But I don’t actually install anything on the container. I tend to always run those containers with the --rm flag to remove them when I exit. Instead I create custom docker images based on the Ubuntu (or the *ux I actually like better) as the tutorial describes.
Second; Docker will not magically behave like a server node. Not in the way an Ubuntu instance on Amazon or Azure does. And at the same time, it will.
Third: If you don’t need a full fledged *ux, use something smaller to begin with. Like Buzybox or Alpine. I just love them, since they give me smaller images and a better control of what the container can do.
Fourth: The most important lesson that I learned (the hard way) was to create images and containers that have a single responsibility. If you need a stack that contains a Webserver, a KeyValue-store and a relational database, it is tempting to install all of them into the same image. If you know that your final deployment will be in a single node, that is fine. But it seldom is the case. I use docker compose to define a stack/application instead where I have separate images and containers for each type. Then I can’t rely on the localhost configuration and instead need to make sure that I can configure the application. In this way, the default is to look for say the DB server ip and port in the configuration using the defined network. But I can by just giving the right environment parameter to the web container on startup use Amazon RDS to host my database. So start creating “production like” environments using Docker as early in the development as possible.
Talking about images, let’s take as an example PHP image, it’s still not clear to should I install my web server on that image? I still think in terms of virtual machines though understand that docker containers are based on layers.