Currently Iā€™m planning to dockerize some web applications but I didnā€™t find a reasonably easy way do create the images to be hosted in my repository so I can pull them on my server.

What I currently have is:

  1. A local computer with a directory where the application that I want to dockerize is located
  2. A ā€œdocker serverā€ running Portainer without shell/ssh access
  3. A place where I can upload/host the Docker images and where I can pull the images from on the ā€œDocker serverā€
  4. Basic knowledge on how to write the needed Dockerfile

What I now need is a sane way to build the images WITHOUT setting up a fully featured Docker environment on the local computer.

Ideally something where I can build the images and upload them but without that something ā€œlittering Docker-related files all over my systemā€.

Something like a VM that resets on every start maybe? So ā€¦ build the image, upload to repository, close the terminal window, and forget that anything ever happened.

What is YOUR solution to create and upload Docker images in a clean and sane way?

37 points

Poorly

permalink
report
reply
5 points

permalink
report
parent
reply
0 points

What does your economic status have to do with creating docker images?

permalink
report
parent
reply
7 points

My code ainā€™t the only thing thatā€™s broke

permalink
report
parent
reply
10 points
*

For the littering part, just type crontab -e and add the following line:

@daily docker system prune -a -f
permalink
report
reply
2 points
*

Careful this will also delete your unused volumes (not attached to a running container because it is stopped for whatever reason counts as unused). For this reason alone, always use bind mounts for volumes you care about.

permalink
report
parent
reply
1 point

Yes.

All my self hosted containers are bound to some volume (since they require reading settings or databases).

permalink
report
parent
reply
1 point
*

as a user with root permission or as root ?

permalink
report
parent
reply
8 points
*

You shouldnā€™t need sudo to run docker, just can create a docker group and add your user to it. This will give you the steps on how to run docker without sudo.

Edit: as pointed out below, please make sure that youā€™re comfortable with giving these permissions to the user youā€™re adding to the docker group.

permalink
report
parent
reply
3 points

run docker without sudo.

Doing that, you effectively give the user account root access without password

docker run --volume /etc:/host_etc debian /bin/bash -> can read/write anything below the hostā€™s /etc directory, including shadow file, etc.

permalink
report
parent
reply
-1 points
*

permalink
report
parent
reply
3 points
*

Genuinely curious, what would the advantages be?

Also, what if the Linux distro does not have systemd?

permalink
report
parent
reply
1 point

I was just making a meme dude. Personally, I like systemd, itā€™s more complicated to learn, I ended up reading books to really learn it properly. Thereā€™s 100% nothing wrong with cron.

One of the reasons I like timers is journalctl integration. I can see everything in one place. Small thing.

permalink
report
parent
reply
1 point

The chances I am going to manage a linux distro without systemd are low, but some systems (arch for example) donā€™t have cron out of the box.

Not that big of a deal since itā€™s easy to translate them all, but thatā€™s one of the reasons why I default to systemd/timer units.

permalink
report
parent
reply
7 points

I use Gitea and a Runner to build Docker images from the projects in the git repo. Since Iā€™m lazy and only have one machine, I just run the runner on the target machine and mount the docker socket.

BTW: If you manage to ā€œlitter your system with docker related filesā€ you fundamentally mis-used Docker. Thatā€™s exactly what Docker is supposed to prevent.

permalink
report
reply
6 points

Self hosting your own CI/CD is the key for OP. Littering is solved too because litter is only a problem on long running servers, which is an anti-pattern in a CI/CD environment.

permalink
report
parent
reply

I already have Forgejo (soft-fork of Gitea) in a Docker container. I guess I need to check how I can access that exact same Docker server where itself is hosted ā€¦

With littering I mean several docker dotfiles and dotdirectories in the userā€™s home directory and other system-wide locations. When I installed Docker on my local computer it created various images, containers, and volumes when created an image.

This is what I want to prevent. Neither do I want nor do I need a fully-featured Docker environment on my local computer.

permalink
report
parent
reply
5 points

Maybe you should read up a bit about how docker works, you seem to misunderstand a lot here.

For example the ā€œvarious imagesā€ are kind of the point of docker. Images are layered, and each layer is its own image, so you might end up with 3 or 4 images despite only building one image.

This is something you canā€™t really prevent. Itā€™s just how docker works.

Anyway, you can mount the docker socket into a container, and using that socket you can then build an image within the running container. Thatā€™s essentially how most ci/cd systems work.

You could maybe look into podman and buildah, as far as I know, these can build images without a running docker daemon. That might be a tad ā€œcleanerā€, but comes with other problems (like no caching).

permalink
report
parent
reply

I have no problem with Docker creating several images and containers and volumes for building a single-image application. The problem is that it does not clean up afterwards and leaves me with multiple things I donā€™t need for anything else.

I also donā€™t care about caching or any ā€œmagicā€ stuff. I just ideally want to run one command (or script doing it for me) to build an image resulting in just this one image without any other traces left. ā€¦ I just like a clean environment and the build process ideally being self-contained.

But Iā€™ll look into your suggestions, thanks!

permalink
report
parent
reply
1 point

Do you mean that you want to build the docker image on one computer, export it to a different computer where itā€™s going to run, and there shouldnā€™t be any traces of the build process on the first computer? Perhaps itā€™s possible with the ā€“output optionā€¦ Otherwise you could write a small script which combines the commands for docker build, export to file, delete local image, and clean up the system.

permalink
report
parent
reply

I want to export the image to my repository/registry and then use it somewhere else. I also donā€™t want to set up a complete docker environment with all the ā€œmagicā€ things. Just build an image and upload it.

permalink
report
parent
reply
6 points

For local testing: build and run tests on whatever computer Iā€™m developing on.

For deployment: I have a self hosted gitlab instance in a kubernetes cluster. It comes with a registry all setup. Push the project, let the cicd pipeline build, test, and deploy through staging into prod.

permalink
report
reply
6 points

Gitlab has a great set of CI tools for deploying docker images, and includes an internal registry of images automatically tied to your repo and available in CI.

permalink
report
reply

Selfhosted

!selfhosted@lemmy.world

Create post

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you donā€™t control.

Rules:

  1. Be civil: weā€™re here to support and learn from one another. Insults wonā€™t be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If itā€™s not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Donā€™t duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (donā€™t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

Community stats

  • 5.1K

    Monthly active users

  • 3.6K

    Posts

  • 81K

    Comments