I want to replace this command with an ansible playbook
'docker build -q --network host -t "ubuntu" . '
I have been going through docker_image module of ansible but couldn't figure it out. Any idea on how to proceed further?
Thanks in advance.
The nearest you can have it is:
---
- name: build the image
docker_image:
name: docker
tag: ubuntu
path: "/yourpath"
state: present
For the --network host, there is a request open in Github to have it.
Related
is there a way to start a podman container with ansible periodically?
I'd like to mix the ansible's cron, and podman modules, like:
- name: Run the DB Migrations docker image
ansible.builtin.cron:
hours: '10'
job:
containers.podman.podman_container:
name: my-podman-container
image: registry.gitlab.com/vilmosnagy/my-container
recreate: true
Yeah, I could write the podman run --rm --name my-podman-container registry.gitlab.com/vilmosnagy/my-container command in the cron module I'm looking for a better way to do this.
Thanks,
I want to use Hadoop from CDH docker image. CDH image is already installed on my machine and I can run it.
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
07a55a9d4cb9 4239cd2958c6 "/usr/bin/docker-quickstart" 18 minutes ago Up 18 minutes 0.0.0.0:32774->7180/tcp, 0.0.0.0:32773->8888/tcp container
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container
172.17.0.2
Local, I am writing an ansible playbook and I need to set Hadoop conf dir in CDH which is: "/etc/hadoop/conf".
How can I set the running docker image in my ansible playbook?
I tried:
- name: run cloudera
docker_container:
name: "container"
image: quickstart/cloudera
command: /usr/bin/docker-quickstart"
state: started
ports:
- 8888:8888
- 7180:7180
But this command runs another docker image and I would like to connect to the running one.
inventory.ini
container ansible_connection=docker
Note: I suggest for the future that you rename your container to something more distinct than container....
example playbook.yml
---
- hosts: container
tasks:
- name: I am a dummy task, write your own
file:
path: /tmp/helloContainer
state: file
Running the playbook
ansible-playbook -i inventory.ini playbook.yml
I have a docker-compose under windows with cap_add and privileges set in order to mount a windows net share in the dockerfile (running a debian) by using cifs.
During the build I always get "Unable to apply new capability set". However, if I get with the bash into the running container I can mount without any problem.
Here is the dockerfile relevant code:
RUN apt-get install cifs-utils -y
RUN mkdir /opt/shared
#RUN mount -v -t cifs //10.20.25.14/external /opt/shared -o
"user=username,password=mypass-,domain=mydm,sec=ntlm"
and this is the docker-compose part:
anaconda:
privileged: true
image: piano_anaconda:latest
security_opt:
- seccomp:unconfined
cap_add:
- SYS_ADMIN
- DAC_READ_SEARCH
build:
context: .
dockerfile: dockerfile_anaconda
I have read this as well but it did not really help to mount within the docker file.
What am I missing here?
Thanks in advance to all for your help.
When using the file circle.yml file to build a docker image I'm trying to pass an environment variable $CIRCLE_PROJECT_USERNAME so that the file is less project specific. Unfortunately Docker build with the tag argument -t fails with:
docker build -t CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH . returned exit code 1
repository name component must match "[a-z0-9]+(?:[._-][a-z0-9]+)*" Action failed: docker build -t CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH .
Circle.yml file:
machine:
environment:
services:
- docker
dependencies:
override:
- docker info
- docker build -t CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH .
test:
override:
- docker run -d $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH
deployment:
hub:
branch: master
commands:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASSWORD
- docker push $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH
deployment:
hub:
branch: develop
commands:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASSWORD
- docker push $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH
Should work, check if the env are actually set and only contain allowed characters:
[a-z0-9]+(?:[._-][a-z0-9]+)*
Edit:
docker build -t CIRCLE_PROJECT_USERNAME ...
Maybe just missing a $ here? ;)
I want to test ELK.
It works fine
BUt when I want to do a
docker-compose up
behind a proxy
docker-compose up --no-recreate
Building kibana
Step 1 : FROM kibana:latest
---> 544887fbfa30
Step 2 : RUN apt-get update && apt-get install -y netcat
---> Running in 794342b9d807
It failed
W: Some index files failed to download. They have been ignored, or old ones used instead.
Is' OK with
docker build --build-arg http_proxy=http://proxy:3128 --build-arg https_proxy=http://proxy:3128 kibana
But when I redo a docker-compose up, il tries to re-build, and failed to pass through proxy
Any help ?
You will need docker-compose 1.6.0-rc1 in order to pass the proxy to your build through docker-compose.
See commit 47e53b4 from PR 2653 for issue 2163.
Move all build related configuration into a build: section in the service.
Example:
web:
build:
context: .
dockerfile: Dockerfile.name
args:
key: value
As mkjeldsen points out in the comments
If key should assume the value of an environment variable of the same name, value can be omitted (docker-compose ARGS):
Especially useful for https_proxy: if the envvar is unset or empty, the builder will not apply proxy, otherwise it will.
I ran into the same problem. What helped me was using the explicit version 2.2 and then build - args and - network as described in the documentation.
VonC is right, it works for me by adding args section under the build lines in docker-compose file:
original:
ssh:
build: ssh/.
container_name: ssh
ports:
- "3000:22"
networks:
vault_net:
ipv4_address: 172.16.238.20
Modified:
ssh:
build:
context: "ssh/."
args:
HTTP_PROXY: http://X.X.X.X:XXXX
HTTPS_PROXY: http://X.X.X.X:XXXX
NO_PROXY: .domain.ltd,127.0.0.1
container_name: ssh
ports:
- "3000:22"
networks:
vault_net:
ipv4_address: 172.16.238.20
Note that I have to add quotes for context since it needs to be formatted as string.
Thanks a lot.
did you try it on clean machine?
docker-machine stop default
docker-machine create -d virtualbox test
docker-machine start test
eval $(docker-machine env test)
docker-compose up