{"id":3222,"date":"2026-05-12T20:54:09","date_gmt":"2026-05-12T11:54:09","guid":{"rendered":"https:\/\/www.next-hop.net\/blog\/hiraga\/?p=3222"},"modified":"2026-05-13T13:09:45","modified_gmt":"2026-05-13T04:09:45","slug":"docker-with-bhyve","status":"publish","type":"post","link":"https:\/\/www.next-hop.net\/blog\/hiraga\/freebsd\/docker-with-bhyve\/","title":{"rendered":"Bhyve\u3092\u5229\u7528\u3057\u3066Docker\u3092\u52d5\u304b\u3059"},"content":{"rendered":"<p>FreeBSD\u3067Docker\u3092\u52d5\u304b\u3059\u5834\u5408\u3001\u3044\u304f\u3064\u304b\u306e\u9078\u629e\u80a2\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u4e00\u756a\u7c21\u5358\u3067\u5b89\u5b9a\u3057\u3066\u3044\u308bBhyve\u30d9\u30fc\u30b9\u3067Docker\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u307e\u3059\u3002<\/p>\n<h2>\u524d\u63d0<\/h2>\n<ul>\n<li>NetBox\u3067\u30a4\u30f3\u30d9\u30f3\u30c8\u30ea\u30fc\u7ba1\u7406<\/li>\n<li>Bhyve\u7ba1\u7406\u306bvm-bhyve\u5229\u7528<\/li>\n<li>Docker\u5b9f\u884c\u7528\u306b\u8efd\u91cf\u306aAlpineLinux virt v3.23.4\u3092\u5229\u7528<\/li>\n<li>AlpineLinux\u306f\u3042\u3048\u3066grub\u30d6\u30fc\u30c8<\/li>\n<\/ul>\n<h2>AlpineLinux\u4eee\u60f3\u74b0\u5883\u69cb\u7bc9<\/h2>\n<h4>roles\/freebsd\/tasks\/vm_bhyve_alpinelinux.yaml<\/h4>\n<pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\r\n- name: Set AlpineLinux variables\r\n  set_fact:\r\n    alpinelinux_org: &quot;https:\/\/dl-cdn.alpinelinux.org\/alpine&quot;\r\n    alpinelinux_ver: &quot;3.23&quot;\r\n    alpinelinux_ver_rev: &quot;4&quot;\r\n    alpinelinux_flavor: &quot;virt&quot;\r\n    alpinelinux_kernel: &quot;virt&quot;\r\n    alpinelinux_arch: &quot;x86_64&quot;\r\n    alpinelinux_host: &quot;docker&quot;\r\n\r\n- name: Set ISO\r\n  set_fact:\r\n    iso: &quot;alpine-{{ alpinelinux_flavor }}-{{ alpinelinux_ver }}.{{ alpinelinux_ver_rev }}-{{ alpinelinux_arch }}.iso&quot;\r\n\r\n- name: Check if {{ iso }} exists\r\n  stat:\r\n    path: &quot;\/vm\/.iso\/{{ iso }}&quot;\r\n  register: iso_file\r\n\r\n- name: Get AlpineLinux ISO\r\n  command: |\r\n    vm iso {{ alpinelinux_org }}\/v{{ alpinelinux_ver }}\/releases\/{{ alpinelinux_arch }}\/{{ iso }}\r\n  register: result\r\n  when:\r\n    - not iso_file.stat.exists\r\n    - vm_bhyve_installed\r\n  changed_when: false\r\n\r\n- name: Check if {{ alpinelinux_host }}.conf exists\r\n  stat:\r\n    path: &quot;\/vm\/{{ alpinelinux_host }}\/{{ alpinelinux_host }}.conf&quot;\r\n  register: conf_file\r\n\r\n- name: Check if template file exists\r\n  stat:\r\n    path: \/vm\/.templates\/alpine.conf\r\n  register: alpine_conf_file\r\n\r\n- name: Check if template file exists\r\n  stat:\r\n    path: \/vm\/.templates\/legacy-alpine.conf\r\n  register: legacy_alpine_conf_file\r\n\r\n- name: Create {{ alpinelinux_host }}\r\n  command: |\r\n    vm create -t alpine -c 2 -m 2G -s 20G {{ alpinelinux_host }}\r\n  register: result\r\n  when:\r\n    - alpine_conf_file.stat.exists\r\n    - not conf_file.stat.exists\r\n    - vm_bhyve_installed\r\n  changed_when: false\r\n\r\n- name: Create {{ alpinelinux_host }}\r\n  command: |\r\n    vm create -t legacy-alpine -c 2 -m 2G -s 20G {{ alpinelinux_host }}\r\n  register: result\r\n  when:\r\n    - legacy_alpine_conf_file.stat.exists\r\n    - not conf_file.stat.exists\r\n    - vm_bhyve_installed\r\n  changed_when: false\r\n\r\n- name: Fix grub_install0\r\n  lineinfile:\r\n    path: &quot;\/vm\/{{ alpinelinux_host }}\/{{ alpinelinux_host }}.conf&quot;\r\n    regexp: &#039;^grub_install0=&quot;linux \/boot\/vmlinuz-vanilla initrd=\/boot\/initramfs-vanilla alpine_dev=cdrom:iso9660 modules\r\n=loop,squashfs,sd-mod,usb-storage,sr-mod&quot;$&#039;\r\n    line: &#039;grub_install0=&quot;linux \/boot\/vmlinuz-{{ alpinelinux_kernel }} initrd=\/boot\/initramfs-{{ alpinelinux_kernel }} a\r\nlpine_dev=cdrom:iso9660 modules=loop,squashfs,sd-mod,usb-storage,sr-mod&quot;&#039;\r\n  when:\r\n    - vm_bhyve_installed\r\n\r\n- name: Fix grub_install1\r\n  lineinfile:\r\n    path: &quot;\/vm\/{{ alpinelinux_host }}\/{{ alpinelinux_host }}.conf&quot;\r\n    regexp: &#039;^grub_install1=&quot;initrd \/boot\/initramfs-vanilla&quot;$&#039;\r\n    line: &#039;grub_install1=&quot;initrd \/boot\/initramfs-{{ alpinelinux_kernel }}&quot;&#039;\r\n  when:\r\n    - vm_bhyve_installed\r\n\r\n- name: Fix grub_run0\r\n  lineinfile:\r\n    path: &quot;\/vm\/{{ alpinelinux_host }}\/{{ alpinelinux_host }}.conf&quot;\r\n    regexp: &#039;^grub_run0=&quot;linux \/boot\/vmlinuz-vanilla root=\/dev\/vda3 modules=ext4&quot;$&#039;\r\n    line: &#039;grub_run0=&quot;linux \/boot\/vmlinuz-{{ alpinelinux_kernel }} root=\/dev\/vda3 modules=ext4&quot;&#039;\r\n  when:\r\n    - vm_bhyve_installed\r\n\r\n- name: Fix grub_run1\r\n  lineinfile:\r\n    path: &quot;\/vm\/{{ alpinelinux_host }}\/{{ alpinelinux_host }}.conf&quot;\r\n    regexp: &#039;^grub_run1=&quot;initrd \/boot\/initramfs-vanilla&quot;$&#039;\r\n    line: &#039;grub_run1=&quot;initrd \/boot\/initramfs-{{ alpinelinux_kernel }}&quot;&#039;\r\n  when:\r\n    - vm_bhyve_installed\r\n\r\n- name: Update {{ alpinelinux_host }} configuration\r\n  blockinfile:\r\n    path: &quot;\/vm\/{{ alpinelinux_host }}\/{{ alpinelinux_host }}.conf&quot;\r\n    block: |\r\n      disk1_type=&quot;ahci-cd&quot;\r\n      disk1_dev=&quot;custom&quot;\r\n      disk1_name=&quot;\/vm\/.iso\/{{ iso }}&quot;\r\n  when:\r\n    - vm_bhyve_installed\r\n\r\n- name: Check if {{ iso }} exists\r\n  stat:\r\n    path: &quot;\/vm\/.iso\/{{ iso }}&quot;\r\n  register: iso_file\r\n\r\n- name: Install {{ alpinelinux_host }}\r\n  command: |\r\n    vm install {{ alpinelinux_host }} {{ iso }}\r\n  register: result\r\n  when:\r\n    - iso_file.stat.exists\r\n    - vm_bhyve_installed\r\n  changed_when: false\r\n\r\n- name: vm_list\r\n  community.general.sysrc:\r\n    name: vm_list\r\n    value: &quot;{{ alpinelinux_host }}&quot;\r\n  when:\r\n    - vm_bhyve_installed\r\n<\/pre>\n<h2>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<h3>\u30b3\u30f3\u30bd\u30fc\u30eb\u30ed\u30b0\u30a4\u30f3<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvm console docker\r\nlogin: root\r\n<\/pre>\n<h3>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u4f5c\u6210<\/h3>\n<p>Bhyve\u306egrub\u304cext4\u306e\u30d6\u30fc\u30c8\u9818\u57df\u304b\u3089\u30ab\u30fc\u30cd\u30eb\u3092\u30d6\u30fc\u30c8\u3067\u304d\u306a\u3044\u306e\u3067\u3001setup-alpine\u5b9f\u884c\u5f8c\u306bext2\u3067\u30d6\u30fc\u30c8\u9818\u57df\u3092\u518d\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<h4>\/setup.sh<\/h4>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/sh\r\nsetup-alpine\r\nmount \/dev\/vda3 \/mnt\r\nmount \/dev\/vda1 \/mnt\/boot\r\nmkdir -p \/tmp\/boot\r\ncp -pr \/mnt\/boot\/* \/tmp\/boot\/\r\numount \/mnt\/boot\r\nmkfs.ext2 -O ^64bit \/dev\/vda1\r\nmount -t ext2 \/dev\/vda1 \/mnt\/boot\r\ncp -pr \/tmp\/boot\/* \/mnt\/boot\/\r\numount \/mnt\/boot\r\nNEW_UUID=`blkid -s UUID -o value \/dev\/vda1`\r\ncp -p \/mnt\/etc\/fstab \/mnt\/etc\/fstab.orig\r\nsed -i &quot;\/\\\/boot\/c\\UUID=${NEW_UUID}\\t\\\/boot\\text2\\trw,relatime\\t0 2&quot; \/mnt\/etc\/fstab\r\numount \/mnt\r\nreboot\r\n<\/pre>\n<h3>\u5b9f\u884c<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n\/setup.sh\r\n<\/pre>\n<h2>Docker<\/h2>\n<h3>Ansible\u306e\u6709\u52b9\u5316<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nssh -l root docker\r\nlogin: root\r\npassword: XXXXXXXXXXXXXXXXXXX\r\napk add python3\r\napk add sshpass\r\nmkdir -p \/root\/.ssh\r\nchmod 700 \/root\/.ssh\r\ncat &gt; \/root\/.ssh\/authorized_keys\r\n\u9375\u3092\u30da\u30fc\u30b9\u30c8\r\n^D\r\n<\/pre>\n<h3>Docker\u306e\u6709\u52b9\u5316<\/h3>\n<h4>roles\/alpinelinux\/tasks\/docker.yaml<\/h4>\n<pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\r\n- name: Update repo\r\n  lineinfile:\r\n    path: \/etc\/apk\/repositories\r\n    regexp: &#039;^#http:\/\/dl-cdn.alpinelinux.org\/alpine\/v{{ alpinelinux_ver }}\/community$&#039;\r\n    line: http:\/\/dl-cdn.alpinelinux.org\/alpine\/v{{ alpinelinux_ver }}\/community\r\n\r\n- name: Update repo\r\n  blockinfile:\r\n    path: \/etc\/apk\/repositories\r\n    block: |\r\n      http:\/\/dl-cdn.alpinelinux.org\/alpine\/edge\/main\r\n      http:\/\/dl-cdn.alpinelinux.org\/alpine\/edge\/community\r\n      http:\/\/dl-cdn.alpinelinux.org\/alpine\/edge\/testing\r\n\r\n- name: Ensure \/etc\/docker directory installed\r\n  file:\r\n    path: \/etc\/docker\r\n    state: directory\r\n    mode: &quot;0755&quot;\r\n\r\n- name: \/etc\/docker\/daemon.json\r\n  copy:\r\n    dest: \/etc\/docker\/daemon.json\r\n    content: |\r\n      {\r\n          &quot;firewall-backend&quot;: &quot;nftables&quot;\r\n      }\r\n\r\n- name: apk add\r\n  command: apk add docker docker-compose\r\n  register: result\r\n\r\n- name: Add net.ipv4.ip_forward=1\r\n  lineinfile:\r\n    path: \/etc\/sysctl.conf\r\n    regexp: &#039;^net.ipv4.ip_forward=&#039;\r\n    line: net.ipv4.ip_forward=1\r\n\r\n- name: Reload sysctl\r\n  command: sysctl -p\r\n\r\n- name: Start docker\r\n  service:\r\n    name: docker\r\n    state: started\r\n\r\n- name: update docker\r\n  command: rc-update add docker boot\r\n<\/pre>\n<h2>\u30ed\u30fc\u30ab\u30eb docker run \u5b9f\u884c\u30c6\u30b9\u30c8<\/h2>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ndocker run --rm hello-world\r\n\r\nHello from Docker!\r\nThis message shows that your installation appears to be working correctly.\r\n\r\nTo generate this message, Docker took the following steps:\r\n 1. The Docker client contacted the Docker daemon.\r\n 2. The Docker daemon pulled the &quot;hello-world&quot; image from the Docker Hub.\r\n    (amd64)\r\n 3. The Docker daemon created a new container from that image which runs the\r\n    executable that produces the output you are currently reading.\r\n 4. The Docker daemon streamed that output to the Docker client, which sent it\r\n    to your terminal.\r\n\r\nTo try something more ambitious, you can run an Ubuntu container with:\r\n $ docker run -it ubuntu bash\r\n\r\nShare images, automate workflows, and more with a free Docker ID:\r\n https:\/\/hub.docker.com\/\r\n\r\nFor more examples and ideas, visit:\r\n https:\/\/docs.docker.com\/get-started\/\r\n<\/pre>\n<h2>\u30ea\u30e2\u30fc\u30c8 docker \u5b9f\u884c\u30b9\u30af\u30ea\u30d7\u30c8<\/h2>\n<h4>docker.sh<\/h4>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/sh\r\n\r\nDOCKER_HOST=&quot;docker&quot;\r\nDOCKER_ARGS=&quot;$*&quot;\r\n\r\nssh -l root $DOCKER_HOST &quot;docker $DOCKER_ARGS&quot;\r\n<\/pre>\n<h2>\u53c2\u8003<\/h2>\n<ul>\n<li><a href=\"https:\/\/hub.docker.com\/\">Docker Hub<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>FreeBSD\u3067Docker\u3092\u52d5\u304b\u3059\u5834\u5408\u3001\u3044\u304f\u3064\u304b\u306e\u9078\u629e\u80a2\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u4e00\u756a\u7c21\u5358\u3067\u5b89\u5b9a\u3057\u3066\u3044\u308bBhyve\u30d9\u30fc\u30b9\u3067Docker\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u307e\u3059\u3002 \u524d\u63d0 NetBox\u3067\u30a4\u30f3\u30d9\u30f3\u30c8\u30ea\u30fc\u7ba1\u7406 Bhyve\u7ba1\u7406\u306bvm-bhyve\u5229\u7528\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.next-hop.net\/blog\/hiraga\/freebsd\/docker-with-bhyve\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-3222","post","type-post","status-publish","format-standard","hentry","category-freebsd"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/posts\/3222"}],"collection":[{"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/comments?post=3222"}],"version-history":[{"count":15,"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/posts\/3222\/revisions"}],"predecessor-version":[{"id":3237,"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/posts\/3222\/revisions\/3237"}],"wp:attachment":[{"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/media?parent=3222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/categories?post=3222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.next-hop.net\/blog\/hiraga\/wp-json\/wp\/v2\/tags?post=3222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}