2

I know that containers are a form of isolation between the app and the host (the managed running process). I also know that container images are basically the package for the runtime environment (hopefully I got that correct). What's confusing to me is when they say that a Docker image doesn't retain state. So if I create a Docker image with a database (like PostgreSQL), wouldn't all the data get wiped out when I stop the container and restart? Why would I use a database in a Docker container?

It's also difficult for me to grasp LXC. On another question page I see:

LinuX Containers (LXC) is an operating system-level virtualization method for running multiple isolated Linux systems (containers) on a single control host (LXC host)

What does that exactly mean? Does it mean I can have multiple versions of Linux running on the same host as long as the host support LXC? What else is there to it?

u84six
  • 4,604
  • 6
  • 38
  • 65
  • 2
    For your first question, check out the [Where to Store Data](https://docs.docker.com/samples/library/mysql/#where-to-store-data) section of the MySQL Docker introduction page. In short, you write data to a location outside of the container, exposed to Docker. – Mako212 Oct 17 '18 at 22:02
  • 1
    Also see the [Manage Application Data page](https://docs.docker.com/storage/) – Mako212 Oct 17 '18 at 22:10
  • So when you're using a database container and it needs to be scaled on demand, what is the process of scaling the runtime and the storage? Do you run multiple containers behind a load balancer and also add more volumes as needed? Are there tools out there that are specifically designed to scale Docker db containers? – u84six Oct 17 '18 at 22:24
  • 1
    I am not an expert on Docker, but a Docker swarm (made up of replicas of a container) will automatically load balance. – Mako212 Oct 17 '18 at 22:28

1 Answers1

1

LXC and Docker, Both are completely different. But we say both are container holders.

There are two types of Containers,

1.Application Containers: Whose main motto is to provide application dependencies. These are Docker Containers (Light Weight Containers). They run as a process in your host and gets all the things done you want. They literally don't need any OS Image/ Boot Up thing. They come and they go in a matter of seconds. You cannot run multiple process/services inside a docker container. If you want, you can do run multiple process inside a docker container, but it is laborious. Here, resources (CPU, Disk, Memory, RAM) will be shared.

2.System Containers: These are fat Containers, means they are heavy, they need OS Images to launch themselves, at the same time they are not as heavy as Virtual Machines, They are very similar to VM's but differ in architecture a bit.

In this, Let us say Ubuntu as a Host Machine, if you have LXC installed and configured in your ubuntu host, You can run a Centos Container, a Ubuntu(with Differnet Version), a RHEL, a Fedora and any linux flavour on top of a Ubuntu Host. You can also run multiple process inside an LXC contianer. Here also resoucre sharing will be done.

So, If you have a huge application running in one LXC Container, it requires more resources, simultaneously if you have another application running inside another LXC container which require less resources. The Container with less requirement will share the resources with the container with more resource requirement.

Answering Your Question:

So if I create a Docker image with a database (like PostgreSQL), wouldn't all the data get wiped out when I stop the container and restart?

You won't create a database docker image with some data to it(This is not recommended). You run/create a container from an image and you attach/mount data to it.

So, when you stop/restart a container, data will never gets lost if you attach that data to a volume as this volume resides somewhere other than the docker container (May be a NFS Server or Host itself).

Does it mean I can have multiple versions of Linux running on the same host as long as the host support LXC? What else is there to it?

Yes, You can do this. We are running LXC Containers in our production.

RajNikhil Marpu
  • 397
  • 2
  • 4
  • 19