Speaking at the Edinburgh International Book Festival, the Pulp frontman revealed he had a cameo role as a cowboy in the “quasi-Western” Asteroid City.
Bryan Cranston, Margot Robbie, Liev Schreiber and Steve Carrell will also be appearing in the film, which focuses on an astronomy convention taking place in a desert town in the 1950s.
Cocker previously recorded a companion album as a “musical extension" of Anderson’s film The French Dispatch. Anderson directed an animated video for the track Aline, a cover of the 1965 Christophe song.
Anderson’s previous films include The Grand Budapest Hotel, Fantastic Mr Fox, The Royal Tenenbaums, Isle of Dogs and Rushmore.
Cocker said: "Wes and I met when he was showing one of his films in London and he asked me to play some records at the party.
"He became friends when I was living in Paris for a while and he had just moved there.
"Myself and Richard Hawley have written a song for his new film Asteroid City, which is coming out next year.
"I’ve got a small cameo role in the film as a cowboy, so there you are, dreams do eventually come true.
"I’ve a lot of respect for the way he makes films. A lot of people say his films are really controlled and maybe think he is a cold person.
"He is actually the complete opposite. The experience of being that film set was quite inspiring.
"There were quite well known Hollywood actors, but everyone was staying in the same hotel and everybody ate together.
"The film is a kind of quasi-Western, so he had this collection of DVDs of films which had some influence on the way he was making the film. You were invited to watch them.
"It felt like he was trying to involve you in the film as much as you wanted to be. He was very inclusive, which I think some people will be surprised by.”