5 ms·
Docker is its own nightmare :/ I just find it weird and confusing. Also, how do you setup a database in docker? Docker does not support persisting data as far
by hasenj 9y ago
Docker is its own nightmare :/
I just find it weird and confusing.
Also, how do you setup a database in docker? Docker does not support persisting data as far as I know. So if you need to restart the thing, all the data will be wiped. At least that's how it seems to be.
- echlebek 9y agoYou are meant to use a storage driver such as aufs or overlay with an attached volume to persist information between container lifetimes. There are a variety of opinions on the goodness of using docker for running a database.
- hasenj 9y agoWhich translates to: I basically don't want to use it. At least not for development. Not as a means to abstract away the setup of something like Postgres; Docker has its own complications when it comes to setting things up, which I must learn _in addition_ to learning everything related to setting up Postgres.
- bschwindHN 9y agoRunning Postgres in a container for development environments is one of the best features of Docker in my opinion. It's really not hard to set up at all. Install docker and docker-compose, write a simple docker-compose.yml file, and then `docker-compose up -d` in the same directory as the docker-compose.yml file. You now have a full Postgres instance running on your machine at localhost:5432. Stop it with `docker compose down` DB files are stored in the `pg` folder in the same directory as docker-compose.yml. You can specify this on the `volumes` property. docker-compose.yml: version: '2' services: pg: image: postgres:9.4.10 ports: - "5432:5432" volumes: - $PWD/pg:/var/lib/postgresql/data/pgdata environment: - PGDATA=/var/lib/postgresql/data/pgdata - POSTGRES_DB=YOUR_DB_NAME_HERE - POSTGRES_USER=YOUR_DB_USER_NAME_HERE - POSTGRES_PASSWORD=YOUR_DB_PASSWORD_HERE
- nh2 9y agoInstead of doing all of that, you could also do it without docker. Simply install postgres via your Linux distro and run e.g.: /usr/lib/postgresql/9.5/bin/postgres -D .mydatadir
- bschwindHN 9y agoSure you can do that, but if your app needs to use other services (Redis, for example) you can easily throw that in the compose file as well, and then it's easy to maintain versions and have every developer be on the same page. This is especially helpful if some developers use OS X or Windows. I don't understand the "all of that" phrasing, as if what I just described was a large amount of work.
- hasenj 9y agoWhy would I want to use redis? My whole point is that I want to simplify my setup, so that I don't need tons of third party servers.
- bschwindHN 9y agoDo you reimplement caching and data storage on every new project? Redis is just one example. Surely in any major project you've made use of a third party server? Maybe not, but tons of projects do and I'm simply describing an easy way to manage those services in a development environment. What's so hard to understand about this?
- ComputerGuru 9y agoHow many people run webwpps with changing version requirements for their _database_? Docker is useful for running components of your own code or for isolation, not for managing versions of core applications like a database or a mail server for most people deploying ready-made apps.
- bschwindHN 9y ago
- pingiun 9y ago> Docker does not support persisting data as far as I know. So if you need to restart the thing, all the data will be wiped. At least that's how it seems to be. In some systems such as kubernetes, data is not saved on a persistent disk. But by default docker containers can retain data. However this is generally solved by using volumes, which you can read about here: https://docs.docker.com/engine/admin/volumes/volumes/ https://docs.docker.com/engine/admin/volumes/volumes/
- piaste 9y agoOther HNers are making it more complicated than it strictly needs to be. Kubernetes and storage drivers are great and all, but we're talking hello world here. So, if you want to keep it simple: docker run postgres --detach --volume /save/my/data/in/this/path:var/lib/postgresql/data That's it. (The --detach is to start it in background. Otherwise it would run in your terminal session and stop when you CTRL-C.) Even if you don't specify a path for the data, the container would save its data in a Docker volume (a file), which doesn't get deleted until you explicitly ask it to. If you stop the container and restart it, it'll reattach to the same volume and find the data. If you delete the container without explicitly deleting its volumes as well, you'll be able to create another postgres container and attach the old volume to it.
- daveguy 9y agoThe instructions on the link I gave are clear about using volumes to persist data. It is a very quick read and definitely worth your time. Ease of postgres deploy is what made me a docker fan.
- hasenj 9y agoDo you understand what it does? Do you understand the common ways it can fail? When it does eventually fail, can you figure out how to fix it?
- daveguy 9y agoFrom postgres perspective, yes I administered pg databases for 10+ years. From a docker perspective, I have been learning over the past couple years, but mostly I have been able to identify failures. Why do you ask?