FreeBSD系统使用docker-compose使用docker容器(没搞定)

一直为FreeBSD下怎么使用docker而发愁,发现竟然也有docker-compose

pkg search compose

docker-compose-1.24.0_4 Define and run multi-container applications with Docker

这个版本据说太老了....没搞定....

安装

复制代码
sudo pkg install docker-compose

需要安装很多依赖库

复制代码
New packages to be INSTALLED:
        docker-compose: 1.24.0_4 [ustc]
        libsodium: 1.0.19 [ustc]
        libyaml: 0.2.5 [ustc]
        py311-async_generator: 1.10_1 [ustc]
        py311-async_timeout: 4.0.3_1 [ustc]
        py311-attrs: 25.3.0 [ustc]
        py311-bcrypt: 4.3.0_2 [ustc]
        py311-cached-property: 1.5.2_1 [ustc]
        py311-certifi: 2025.8.3 [ustc]
        py311-cffi: 1.17.1 [ustc]
        py311-charset-normalizer: 3.4.3 [ustc]
        py311-colorama: 0.4.6 [ustc]
        py311-cryptography: 44.0.3_3,1 [ustc]
        py311-curio: 1.6_1 [ustc]
        py311-docker: 7.1.0 [ustc]
        py311-docker-pycreds: 0.4.0_1 [ustc]
        py311-dockerpty: 0.4.1_2 [ustc]
        py311-docopt: 0.6.2_2 [ustc]
        py311-idna: 3.10 [ustc]
        py311-jsonschema: 4.25.1 [ustc]
        py311-jsonschema-specifications: 2025.4.1 [ustc]
        py311-outcome: 1.3.0_2 [ustc]
        py311-paramiko: 3.5.1 [ustc]
        py311-pyasn1: 0.6.0 [ustc]
        py311-pycparser: 2.22 [ustc]
        py311-pynacl: 1.5.0_2 [ustc]
        py311-pysocks: 1.7.1_1 [ustc]
        py311-python-socks: 2.7.2 [ustc]
        py311-pyyaml: 6.0.1_1 [ustc]
        py311-referencing: 0.36.2 [ustc]
        py311-requests: 2.32.5 [ustc]
        py311-rpds-py: 0.27.1 [ustc]
        py311-sniffio: 1.3.1 [ustc]
        py311-sortedcontainers: 2.4.0_1 [ustc]
        py311-texttable: 1.7.0_1 [ustc]
        py311-trio: 0.31.0 [ustc]
        py311-typing-extensions: 4.15.0 [ustc]
        py311-urllib3: 1.26.20,1 [ustc]
        py311-websocket-client: 1.8.0 [ustc]
        py311-wheel: 0.45.1 [ustc]

Number of packages to be installed: 40

The process will require 39 MiB more space.
7 MiB to be downloaded.

安装之后输出很多提示信息

复制代码
Message from py311-urllib3-1.26.20,1:

--
Since version 1.25 HTTPS connections are now verified by default which is done
via "cert_reqs = 'CERT_REQUIRED'".  While certificate verification can be
disabled via "cert_reqs = 'CERT_NONE'", it's highly recommended to leave it on.

Various consumers of net/py-urllib3 already have implemented routines that
either explicitly enable or disable HTTPS certificate verification (e.g. via
configuration settings, CLI arguments, etc.).

Yet it may happen that there are still some consumers which don't explicitly
enable/disable certificate verification for HTTPS connections which could then
lead to errors (as is often the case with self-signed certificates).

In case of an error one should try first to temporarily disable certificate
verification of the problematic urllib3 consumer to see if that approach will
remedy the issue.
=====
Message from py311-dockerpty-0.4.1_2:

--
===>   NOTICE:

The py311-dockerpty port currently does not have a maintainer. As a result, it is
more likely to have unresolved issues, not be up-to-date, or even be removed in
the future. To volunteer to maintain this port, please create an issue at:

https://bugs.freebsd.org/bugzilla

More information about port maintainership is available at:

https://docs.freebsd.org/en/articles/contributing/#ports-contributing
=====
Message from docker-compose-1.24.0_4:

--
===>   NOTICE:

The docker-compose port currently does not have a maintainer. As a result, it is
more likely to have unresolved issues, not be up-to-date, or even be removed in
the future. To volunteer to maintain this port, please create an issue at:

https://bugs.freebsd.org/bugzilla

More information about port maintainership is available at:

运行

创建文件

创建一个测试目录mkdir testdocker

cd testdocker目录

创建app.py文件

python 复制代码
import time

import redis
from flask import Flask

app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)

def get_hit_count():
    retries = 5
    while True:
        try:
            return cache.incr('hits')
        except redis.exceptions.ConnectionError as exc:
            if retries == 0:
                raise exc
            retries -= 1
            time.sleep(0.5)

@app.route('/')
def hello():
    count = get_hit_count()
    return f'Hello World! I have been seen {count} times.\n'

创建一个文件requirements.txt

python 复制代码
flask
redis

创建文件Dockerfile

python 复制代码
# syntax=docker/dockerfile:1
FROM python:3.10-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 5000
COPY . .
CMD ["flask", "run", "--debug"]

定义服务

创建文件compose.yaml (后来知道需要创建成docker-compose.yaml文件名才可以)

python 复制代码
services:
  web:
    build: .
    ports:
      - "8000:5000"
  redis:
    image: "redis:alpine"

我这边需要文件docker-compose.yaml ,修改文件名字

python 复制代码
cp compose.yaml  docker-compose.yaml

编译运行(失败)

python 复制代码
docker compose up

因为没成功,后面又尝试了使用python3.12的新环境,也是失败。

安装python3.12环境

python 复制代码
sudo pkg install pyenv
pyenv install   miniconda3-3.12-25.7.0-2

忘记了,FreeBSD下不能直接安装miniconda,那就安装3.12版本好了

发现已经pyenv安装了3.12版本,这时候进入bash,写.bashrc文件:

激活

source .bashrc

这时候就是python3.12环境了。

这时候发现docker-compose还是1.24版本,上pypi.org,发现已经好几年没有更新了,看来没法用了。

先放弃这个了。

尝试

尝试一 编译

寻找github源代码:

https://github.com/docker/compose/releases

以后再去做。

尝试二Vagrant 平替

使用vagrant

好像也不行,很多项目是用docker-compose up的,vagrant不能平替

尝试三 docker-composer-v2

docker-composer-v2

装上了,但是没有啊

python 复制代码
pip install docker-composer-v2

看不到有docker-composer-v2

最终放弃

调试

启动报错Can't find a suitable configuration file in this directory or any parent. Are you in the right directory?

skywalk@fb5:~/work/testdocker $ docker-compose up

ERROR:

Can't find a suitable configuration file in this directory or any

parent. Are you in the right directory?

Supported filenames: docker-compose.yml, docker-compose.yaml

需要文件docker-compose.yaml ,修改文件名字

python 复制代码
cp compose.yaml  docker-compose.yaml

搞定

启动报错Unsupported config option for services: 'redis'

skywalk@fb5 \~/work/testdocker$ docker-compose-3.11 up

ERROR: The Compose file './docker-compose.yaml' is invalid because:

Unsupported config option for services: 'redis'

发现有一个1.25版本,一个3.11版本,

在docker-compose.yaml文件中加入:

python 复制代码
version: '3.11'

变成新的报错:

报错TypeError: kwargs_from_env() got an unexpected keyword argument 'ssl_version'

python 复制代码
docker-compose-3.11 up
Traceback (most recent call last):
  File "/usr/local/bin/docker-compose-3.11", line 33, in <module>
    sys.exit(load_entry_point('docker-compose==1.24.0', 'console_scripts', 'docker-compose')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/compose/cli/main.py", line 71, in main
    command()
  File "/usr/local/lib/python3.11/site-packages/compose/cli/main.py", line 124, in perform_command
    project = project_from_options('.', options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/compose/cli/command.py", line 33, in project_from_options
    return get_project(
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/compose/cli/command.py", line 121, in get_project
    client = get_client(
             ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/compose/cli/command.py", line 92, in get_client
    client = docker_client(
             ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/compose/cli/docker_client.py", line 97, in docker_client
    kwargs = kwargs_from_env(environment=environment, ssl_version=tls_version)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: kwargs_from_env() got an unexpected keyword argument 'ssl_version'

发现这个还是1.24版本

python 复制代码
docker-compose-3.11 -v
docker-compose version 1.24.0, build 0aa5906
[skywalk@fb5 ~/work/testdocker]$
相关推荐
张忠琳8 小时前
【NVIDIA】 NVIDIA Container Toolkit v1.19.1 — OCI 模块超深度分析之三
云原生·容器·架构·kubernetes·nvidia
Elastic 中国社区官方博客10 小时前
将你的 Grafana Kubernetes 仪表板迁移到 Elastic Observability:相同的 PromQL,30 倍更快的查询
大数据·人工智能·elasticsearch·搜索引擎·容器·kubernetes·grafana
风曦Kisaki12 小时前
#企业级docker私有仓库构建:harbor仓库与阿里云镜像仓库
阿里云·docker·容器
期待着201312 小时前
docker 安装 ,在centos7.9
运维·docker·容器
骑上单车去旅行15 小时前
Docker Compose 命令完全指南:从构建到运维
docker·容器·eureka
前端Baymax16 小时前
K8s PodCrashLoopBackOff假阳性排查
云原生·容器·kubernetes
spider_xcxc16 小时前
K8s 部署学习笔记
docker·容器·kubernetes·云计算·k8s
java_logo16 小时前
Docker Compose 部署 Apache Superset:轻松搭建开源 BI 平台
docker·开源·apache·superset·轩辕镜像·superset部署方案·docker superset
zy happy16 小时前
VMware虚拟机添加新的硬盘
java·linux·jvm·docker
阿标在干嘛1 天前
从物理机到K8s:政策快报平台的容器化部署实践
云原生·容器·kubernetes