Closed tylerauerbeck closed 10 months ago
Just define exposed_ports
or piblished_ports
in your molecule config, depending on what you need.
Thanks @sshnaidm . Is this documented anywhere? I combed through as much of the molecule docs as I could and even grepped through the repo and only found this within the code. Just want to make sure I'm not missing something simple here.
For anyone else that ends up here, you'll want your molecule.yml
to look something like this:
---
</snip>
platforms:
- name: instance-keycloak
image: docker.io/jboss/keycloak:9.0.3
published_ports:
- 8080/tcp
- 8443/tcp
</snip>
I don't see any docs here at all, tbh.
That' what I noticed as well. Would this be the place to have those types of docs? Or does those belong in the molecule core ? Happy to help start creating those wherever they may need to be -- just probably worth a chat of what should be included and where they need to go.
it seems not work
molecule --version
molecule 3.5.2 using python 3.9
ansible:2.11.6
delegated:3.5.2 from molecule
docker:1.1.0 from molecule_docker requiring collections: community.docker>=1.9.1
hetznercloud:1.3.0 from molecule_hetznercloud
vagrant:0.6.3 from molecule_vagrant
and config bellow
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: instance
image: docker.io/pycontribs/centos:7
published_ports:
- 8000/tcp
- 80/tcp
pre_build_image: true
provisioner:
name: ansible
verifier:
name: goss
it's only ok inside container...
[root@instance /]# curl -I http://localhost:8000
HTTP/1.1 200 OK
Host: localhost:8000
Date: Sat, 18 Dec 2021 08:35:55 GMT
Connection: close
X-Powered-By: PHP/8.1.1
Content-type: text/html; charset=UTF-8
@spham
You need to verify which port that "published_port" selected for your host machine.
docker ps
should reveal something like 0.0.0.0:59175->8500/tcp
There is a complete docker example here: https://molecule.readthedocs.io/en/2.13.1/configuration.html#docker
thank you
Ports in the container are exposed on the localhost, and it's custom to use a mapping to avoid the Address already in use
bind error when your container starts listening. This fragment of molecule.yml
(v3) is for a web server:
platforms:
- name: ubi8
image: registry.access.redhat.com/ubi8/ubi-init
pre_build_image: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
capabilities:
- CAP_NET_BIND_SERVICE
command: "/usr/sbin/init"
published_ports:
- 127.0.0.1:8000:80
Is there any configuration that allows for the tuning of exposed ports? I'm looking to try to run a container image that contains my API and then allows molecule to test my roles out to see if the expected actions/outputs are completed.