@@ -523,6 +523,17 @@ false, "AttachStdout": true, "Cmd": ["gunicorn", "--bind", ":8888",
523
523
----
524
524
525
525
TODO: sort out macos M1/arch issues, `docker build --platform linux/amd64` etc.
526
+ ////
527
+ - name: Build container image locally
528
+ community.docker.docker_image:
529
+ name: superlists
530
+ source: build
531
+ state: present
532
+ build:
533
+ path: ../Dockerfile
534
+ platform: linux/amd64
535
+ delegate_to: 127.0.0.1
536
+ ////
526
537
527
538
Looks ok! Let's see if that worked?
528
539
@@ -574,6 +585,7 @@ config either.
574
585
DJANGO_DEBUG_FALSE=1
575
586
DJANGO_SECRET_KEY="{{ secret_key }}"
576
587
DJANGO_ALLOWED_HOST="{{ host }}"
588
+
577
589
----
578
590
====
579
591
@@ -583,7 +595,8 @@ DJANGO_ALLOWED_HOST="{{ host }}"
583
595
====
584
596
[source,yaml]
585
597
----
586
-
598
+ - name: Import container image on server
599
+ [...]
587
600
588
601
- name: Ensure .env file exists
589
602
ansible.builtin.template:
@@ -594,6 +607,13 @@ DJANGO_ALLOWED_HOST="{{ host }}"
594
607
secret_key: "{{ lookup('password', '/dev/null length=32 chars=ascii_letters,digits') }}"
595
608
force: false # do not recreate file if it already exists.
596
609
610
+ - name: Run container
611
+ community.docker.docker_container:
612
+ name: superlists
613
+ image: superlists
614
+ state: started
615
+ recreate: true
616
+ env_file: ~/superlists.env
597
617
----
598
618
====
599
619
@@ -616,95 +636,33 @@ show ssh, curl localhosts maybe.
616
636
====
617
637
[source,yaml]
618
638
----
619
- - name: Allow nonroot user to bind to port 80
620
- ansible.posix.sysctl:
621
- name: net.ipv4.ip_unprivileged_port_start
622
- value: 80
623
- reload: true
624
- become: true
625
-
626
639
- name: Run container
627
- containers.podman.podman_container :
640
+ community.docker.docker_container :
628
641
name: superlists
629
642
image: superlists
630
643
state: started
631
644
recreate: true
632
- env_file: /superlists.env
645
+ env_file: ~ /superlists.env
633
646
ports: 80:8888
634
647
----
635
648
====
636
649
637
650
638
- ==== Using Systemd to Make Sure Our Container Starts on Boot
651
+ ////
652
+ ==== Making Sure Our Container Starts on Boot
639
653
640
- ((("Systemd")))
641
654
((("Container", "automatic booting/reloading of")))
642
655
Our final step is to make sure
643
656
that the server starts up our container automatically on boot,
644
657
and reloads it automatically if it crashes.
645
658
646
- Ansible and the podman plugins have some modules for this:
647
-
648
-
649
- [role="sourcecode"]
650
- .infra/ansible-provision.yaml (ch11l006)
651
- ====
652
- [source,yaml]
653
- ----
654
- - name: Create container
655
- containers.podman.podman_container:
656
- name: superlists
657
- image: superlists
658
- state: stopped
659
- recreate: true
660
- env_file: ~/superlists.env
661
- ports: 80:8888
662
-
663
- - name: Generate Systemd config file
664
- containers.podman.podman_generate_systemd:
665
- name: superlists
666
- dest: ~/.config/systemd/user/
667
-
668
- - name: Container must be started and enabled on systemd
669
- ansible.builtin.systemd:
670
- name: container-superlists
671
- daemon_reload: true
672
- state: started
673
- enabled: true
674
- ----
675
- ====
659
+ (used to need systemd, now you can just set restart_policy.
660
+ ////
676
661
677
662
678
- ----
679
- vagrant@ubuntu-jammy:~$ cat ~/.config/systemd/user/container-superlists.service
680
- # container-superlists.service
681
- # autogenerated by Podman 3.4.4
682
- # Wed Oct 25 10:55:38 UTC 2023
683
-
684
- [Unit]
685
- Description=Podman container-superlists.service
686
- Documentation=man:podman-generate-systemd(1)
687
- Wants=network-online.target
688
- After=network-online.target
689
- RequiresMountsFor=/run/user/1000/containers
690
-
691
- [Service]
692
- Environment=PODMAN_SYSTEMD_UNIT=%n
693
- Restart=on-failure
694
- TimeoutStopSec=70
695
- ExecStart=/usr/bin/podman start superlists
696
- ExecStop=/usr/bin/podman stop -t 10 superlists
697
- ExecStopPost=/usr/bin/podman stop -t 10 superlists
698
- PIDFile=/run/user/1000/containers/overlay-containers/c058e368b446388cf3b3faecdf1d8186d14d8b0a01fbf64bfca5714ae56d42fe/userdata/conmon.pid
699
- Type=forking
700
-
701
- [Install]
702
- WantedBy=default.target
703
- ----
663
+ === Mounting the database on the server
704
664
705
- Systemd is joyously simple to configure (especially if you've ever had the
706
- dubious pleasure of writing an `init.d` script), and is fairly
707
- self-explanatory.
665
+ TODOOooo
708
666
709
667
710
668
[role="small-code"]
@@ -723,12 +681,14 @@ A few more places to look and things to try, now that we've introduced
723
681
Podman and Systemd into the mix, should things not go according to plan:
724
682
725
683
- You can check the Container logs using
726
- `podman logs superlists`.
727
- ((("debugging", "Podman")))
684
+ `docker logs superlists`.
685
+
686
+ - You can get detailed info on the Container using
687
+ `docker inspect superlists`.
728
688
729
- - You can check the Systemd logs using
730
- `journalctl --user -u container- superlists`.
731
- ((("debugging", "Systemd ")))
689
+ - And you can inspect the image with
690
+ `docker image inspect superlists`.
691
+ ((("debugging", "Docker ")))
732
692
733
693
734
694
*******************************************************************************
0 commit comments