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 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]$ ```

相关推荐
hanyi_qwe3 分钟前
K8S网络和基本命令 【 K8S (二)】
网络·容器·kubernetes
德育处主任4 分钟前
『NAS』中午煮什么?Cook
前端·docker
叽里咕噜怪33 分钟前
Pod的详解与进阶
运维·容器·kubernetes
腥臭腐朽的日子熠熠生辉1 小时前
nest js docker 化全流程
开发语言·javascript·docker
酒醉的胡铁1 小时前
Docker Desktop 数据迁移完整流程(Windows 10/11 x64)
windows·docker·容器
纯洁的小魔鬼1 小时前
Dockerfile 指令
docker·镜像·dockerfile
❀͜͡傀儡师1 小时前
Kubernetes 1.34.3部署PostgresSQL的v18.1
云原生·容器·kubernetes·postgressql
Y.O.U..1 小时前
Kubernetes-资源清单(1)
容器·kubernetes
释怀不想释怀1 小时前
Docker(安装软件)
运维·docker·容器
超龄超能程序猿2 小时前
Docker常用中间件部署笔记:MongoDB、Redis、MySQL、Tomcat快速搭建
笔记·docker·中间件